-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
class.__annotations__ gives weird value when using built-in type keywords as attribute #122937
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
Comments
This is how names and scopes work in Python.
Closing, since there were multiple issues about it and the anwser is always the same :) |
Should anything be added to the docs (I don't know where) to explain this better? |
For reference, the previous issues where this has been raised are:
It does seem to be coming up more and more regularly (for whatever reason), so if we can explain it better, that would be great... There's already documentation on this at https://docs.python.org/3/reference/simple_stmts.html#annassign, which is an appropriate place for this to be documented (since it's to do with core language semantics), but it's almost certainly not where beginners will think to look. |
Maybe in https://docs.python.org/3/howto/annotations.html and link from I would be happy to add this note! |
I have also submitted issues to pycharm. If implemented, it should help others understand this in the future. https://youtrack.jetbrains.com/issue/PY-75106/type-annotation-security-check-for-shadowing-name |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
returns:
{'int': 1, 'normal': 1}
returns:
{'int_': int, 'normal': int}
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux, Windows
Linked PRs
The text was updated successfully, but these errors were encountered: