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

F821 false positive: dict.__dict__['fromkeys'] #9307

Closed
AA-Turner opened this issue Dec 29, 2023 · 3 comments
Closed

F821 false positive: dict.__dict__['fromkeys'] #9307

AA-Turner opened this issue Dec 29, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@AA-Turner
Copy link
Contributor

AA-Turner commented Dec 29, 2023

Ruff doesn't like classmethod descriptors, or seems to think that they're undefined, which is rather odd.

a = type({}).__dict__['fromkeys']
b = dict.__dict__['fromkeys']
assert a is b

Saving the above to bug.py, and running only with F821:

PS I:\Development> ruff -V
ruff 0.1.9
PS I:\Development> ruff --isolated --show-source --select F821 bug.py
bug.py:2:20: F821 Undefined name `fromkeys`
  |
1 | a = type({}).__dict__['fromkeys']
2 | b = dict.__dict__['fromkeys']
  |                    ^^^^^^^^ F821
3 | assert a is b
  |

Found 1 error.

Note only the second line yields an error -- using type({}) as an indirection for dict solves the issue.

A

@charliermarsh
Copy link
Member

Thanks — I’m guessing it thinks it’s a type annotation, as when subscripting dict directly.

@charliermarsh charliermarsh added the bug Something isn't working label Dec 29, 2023
@charliermarsh charliermarsh self-assigned this Dec 29, 2023
@charliermarsh
Copy link
Member

Closed by #9309.

@AA-Turner
Copy link
Contributor Author

Thanks Charlie!

A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants