Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ repos:
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.14.0]
additional_dependencies:
[flake8-bugbear==22.10.27, flake8-typing-imports==1.14.0]
exclude: *fixtures
- repo: local
hooks:
Expand Down
16 changes: 6 additions & 10 deletions pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def visit_default(self, node: nodes.NodeNG) -> None:
tolineno = node.tolineno
assert tolineno, node
lines: list[str] = []
for line in range(line, tolineno + 1):
for line in range(line, tolineno + 1): # noqa: B020
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the warning here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Loop control variable overrides iterable it iterates' (It's by design)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? Can't for line be for index?
The iterable value just seems to be a integer that's called line.

Copy link
Copy Markdown
Member Author

@Pierre-Sassoulas Pierre-Sassoulas Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not touch this, my goal is to add flake8 bugbear not "fix" all legacy issues (especially when the fix is not trivial and the code is working well).

self._visited_lines[line] = 1
try:
lines.append(self._lines[line].rstrip())
Expand Down Expand Up @@ -676,15 +676,11 @@ def check_lines(
if tokens.type(line_start) != tokenize.STRING:
self.check_trailing_whitespace_ending(line, lineno + offset)

# hold onto the initial lineno for later
potential_line_length_warning = False
for offset, line in enumerate(split_lines):
# this check is purposefully simple and doesn't rstrip
# since this is running on every line you're checking it's
# advantageous to avoid doing a lot of work
if len(line) > max_chars:
potential_line_length_warning = True
break
# This check is purposefully simple and doesn't rstrip since this is running
# on every line you're checking it's advantageous to avoid doing a lot of work
potential_line_length_warning = any(
len(line) > max_chars for line in split_lines
)
Comment thread
Pierre-Sassoulas marked this conversation as resolved.

# if there were no lines passing the max_chars config, we don't bother
# running the full line check (as we've met an even more strict condition)
Expand Down
10 changes: 5 additions & 5 deletions pylint/checkers/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,16 +834,16 @@ def check_for_concatenated_strings(

def process_string_token(self, token: str, start_row: int, start_col: int) -> None:
quote_char = None
index = None
for index, char in enumerate(token):
for _index, char in enumerate(token):
if char in "'\"":
quote_char = char
break
if quote_char is None:
return

prefix = token[:index].lower() # markers like u, b, r.
after_prefix = token[index:]
# pylint: disable=undefined-loop-variable
prefix = token[:_index].lower() # markers like u, b, r.
after_prefix = token[_index:]
# pylint: enable=undefined-loop-variable
# Chop off quotes
quote_length = (
3 if after_prefix[:3] == after_prefix[-3:] == 3 * quote_char else 1
Expand Down
5 changes: 4 additions & 1 deletion pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,10 @@ def visit_call(self, node: nodes.Call) -> None:

# 3. Match the **kwargs, if any.
if node.kwargs:
for i, [(name, defval), assigned] in enumerate(parameters):
# TODO: It's possible to remove this disable by using dummy-variables-rgx
# see https://github.com/PyCQA/pylint/pull/7697#discussion_r1010832518
# pylint: disable-next=unused-variable
for i, [(name, _defval), _assigned] in enumerate(parameters):
Comment thread
DanielNoord marked this conversation as resolved.
# Assume that *kwargs provides values for all remaining
# unassigned named parameters.
if name is not None:
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def only_required_for_messages(
def store_messages(
func: AstCallbackMethod[_CheckerT, _NodeT]
) -> AstCallbackMethod[_CheckerT, _NodeT]:
setattr(func, "checks_msgs", messages)
func.checks_msgs = messages # type: ignore[attr-defined]
return func

return store_messages
Expand Down
8 changes: 5 additions & 3 deletions pylint/lint/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
from pylint.constants import PYLINT_HOME
from pylint.utils import LinterStats

PYLINT_HOME_AS_PATH = Path(PYLINT_HOME)


def _get_pdata_path(
base_name: Path, recurs: int, pylint_home: Path = Path(PYLINT_HOME)
base_name: Path, recurs: int, pylint_home: Path = PYLINT_HOME_AS_PATH
) -> Path:
# We strip all characters that can't be used in a filename
# Also strip '/' and '\\' because we want to create a single file, not sub-directories
# We strip all characters that can't be used in a filename. Also strip '/' and
# '\\' because we want to create a single file, not sub-directories.
underscored_name = "_".join(
str(p.replace(":", "_").replace("/", "_").replace("\\", "_"))
for p in base_name.parts
Expand Down
6 changes: 4 additions & 2 deletions pylint/message/message_definition_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def register_message(self, message: MessageDefinition) -> None:
self._msgs_by_category[message.msgid[0]].append(message.msgid)

# Since MessageDefinitionStore is only initialized once
# and the arguments are relatively small in size we do not run the
# and the arguments are relatively small we do not run the
# risk of creating a large memory leak.
# See discussion in: https://github.com/PyCQA/pylint/pull/5673
@functools.lru_cache(maxsize=None) # pylint: disable=method-cache-max-size-none
@functools.lru_cache( # pylint: disable=method-cache-max-size-none # noqa: B019
maxsize=None
)
def get_message_definitions(self, msgid_or_symbol: str) -> list[MessageDefinition]:
"""Returns the Message definition for either a numeric or symbolic id.

Expand Down
1 change: 1 addition & 0 deletions requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# in .pre-commit-config.yaml
black==22.10.0
flake8==5.0.4
flake8-bugbear==22.10.27
flake8-typing-imports==1.14.0
isort==5.10.1
mypy==0.982
10 changes: 7 additions & 3 deletions tests/test_check_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,20 @@ def test_linter_with_unpickleable_plugins_is_pickleable(self) -> None:
linter.load_plugin_modules(["pylint.extensions.overlapping_exceptions"])
try:
dill.dumps(linter)
assert False, "Plugins loaded were pickle-safe! This test needs altering"
raise AssertionError(
"Plugins loaded were pickle-safe! This test needs altering"
)
except (KeyError, TypeError, PickleError, NotImplementedError):
pass

# And expect this call to make it pickle-able
linter.load_plugin_configuration()
try:
dill.dumps(linter)
except KeyError:
assert False, "Cannot pickle linter when using non-pickleable plugin"
except KeyError as exc:
raise AssertionError(
"Cannot pickle linter when using non-pickleable plugin"
) from exc

def test_worker_check_sequential_checker(self) -> None:
"""Same as test_worker_check_single_file_no_checkers with SequentialTestChecker."""
Expand Down