Skip to content

[flake8-comprehensions] Handle builtins at top of file correctly for unnecessary-dict-comprehension-for-iterable (C420) - #15837

Merged
dylwil3 merged 4 commits into
astral-sh:mainfrom
dylwil3:dict-comp
Jan 30, 2025
Merged

dylwil3 merged 4 commits into
astral-sh:mainfrom
dylwil3:dict-comp

Conversation

@dylwil3

@dylwil3 dylwil3 commented Jan 30, 2025

Copy link
Copy Markdown
Collaborator

Builtin bindings are given a range of 0..0, which causes strange behavior when range checks are made at the top of the file. In this case, the logic of the rule demands that the value of the dict comprehension is not self-referential (i.e. it does not contain definitions for any of the variables used within it). This logic was confused by builtins which looked like they were defined "in the comprehension", if the comprehension appeared at the top of the file.

Closes #15830

@dylwil3 dylwil3 added bug An issue describing something that isn't working, or a PR that fixes a bug preview Related to preview-mode features labels Jan 30, 2025

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow, what a bug! 😄

@github-actions

github-actions Bot commented Jan 30, 2025 •

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3
dylwil3 merged commit 4f2aea8 into astral-sh:main Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug preview Related to preview-mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C420 false negative at the start of input for builtin static values

2 participants