Skip to content
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

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

Merged
merged 4 commits into from
Jan 30, 2025

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Jan 30, 2025

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 Something isn't working preview Related to preview mode features labels Jan 30, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Wow, what a bug! 😄

Copy link
Contributor

github-actions bot commented Jan 30, 2025

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
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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