-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: ast.NameConstant missing fields #14353
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
Open
hunterhogan
wants to merge
1
commit into
python:main
Choose a base branch
from
hunterhogan:astNameConstant
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think these attributes are already inherited from
Constant
? Or am I missing something?typeshed/stdlib/ast.pyi
Lines 1092 to 1096 in 3f727b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly, I don't know.
Elephant
By my count, there are five (deprecated) subclasses of
ast.Constant
. Of the five, only NameConstant has those two "attributes". (I'm intentionally avoiding_fields
.)The three in the first comment above have "attributes", and their attributes are defined in ast.pyi. Similarly,
ast.Ellipsis
does not seem to inherit anything fromast.Constant
. Those things point towards a desire to add them to the stub.Rhino
On the other hand, I don't know where
ast.NameConstant
is. I mean, it's not in Python.asdl, and I haven't searched super hard, but I don't know how any of the deprecated classes come to "exist". I just looked more closely at ast.py, and it seems to be flawed, also.https://github.com/python/cpython/blob/1e3466a1ae5bdcee42a3dfdbd8aaa17135a6ecc2/Lib/ast.py#L605-L622
It doesn't name the fields, but the interpreter knows the fields exist.
Elephino
So, I just now did
_field_types
on everything, and evenast.Ellipsis
seems to have inherited fromast.Constant
!I feel like the stub file helps to provide clarity and precision. If that is a goal, then I feel it suggests to add the "attributes" and their types.
On the other hand, I feel that the stub file should not be used to fix code that could be fixed directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, it is not flawed because the intention was to let
ast.NameConstant
inherit fromast.Constant
but to override the inheritance in the other four subclasses. But_field_types
is still messed up for those four subclasses. Malkovich Malkovich Malkovich.