Skip to content

Fix crash caused by invalid format strings in .format context #10300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Resolve pylint too-many-branches
  • Loading branch information
zenlyj committed Mar 23, 2025
commit 2b16fcf854b0802edc62801e8be810f832ff3fff
19 changes: 10 additions & 9 deletions pylint/checkers/refactoring/recommendation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,12 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
keyword = utils.safe_infer(keyword.value)

# If lists of more than one element are being unpacked
if isinstance(keyword, nodes.Dict):
if len(keyword.items) > 1 and len(keyword_args) > 1:
return
if (
isinstance(keyword, nodes.Dict)
and len(keyword.items) > 1
and len(keyword_args) > 1
):
return
Comment on lines -415 to +425
Copy link
Member

Choose a reason for hiding this comment

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

Nice !


# If all tests pass, then raise message
self.add_message(
Expand Down Expand Up @@ -447,12 +450,10 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
inferred_right = utils.safe_infer(node.parent.right)

# If dicts or lists of length > 1 are used
if isinstance(inferred_right, nodes.Dict):
if len(inferred_right.items) > 1:
return
elif isinstance(inferred_right, nodes.List):
if len(inferred_right.elts) > 1:
return
if isinstance(inferred_right, nodes.Dict) and len(inferred_right.items) > 1:
return
if isinstance(inferred_right, nodes.List) and len(inferred_right.elts) > 1:
return

# If all tests pass, then raise message
self.add_message(
Expand Down
Loading