-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Red Knot - Add symbol flags #11134
Red Knot - Add symbol flags #11134
Conversation
f7bc5fd
to
085df6e
Compare
|
accc1f8
to
94b9e17
Compare
6b297b0
to
e9f72ef
Compare
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.
Looks good! Couple comments.
…roduces them Co-authored-by: Carl Meyer <carl@astral.sh>
…hat introduces them
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.
Awesome!
Couple comments on the PR description:
- It says three flags are supported, but it seems like just two?
- This is more a forward-looking comment for the TODOs, but I realized from some conversation this morning that we will probably want to track both
CellVar
andCellVarAssigned
as separate kinds, where the former is "defined in current scope, used in at least one nested scope" and the latter is "defined in current scope, defined and marked_nonlocal in at least one nested scope", because the latter will have different implications for type checking.
That was a typo of "these". Sorry. I've added a commit for the other variant of Kind. |
Symbol.flag
bitfield. Populates it from (the three renamed)add_or_update_symbol*
methods.IS_DEFINED
is set in a scope where a variable is defined.IS_USED
is set in a scope where a variable is referenced. (To have both this andIS_DEFINED
would require two separate appearances of a variable in the same scope-- one def and one use.)MARKED_GLOBAL
andMARKED_NONLOCAL
are not yet implemented. (TODO: While traversing, if you find these declarations, add these flags to the variable.)Symbol.kind
field (commented) and the data structure which will populate it:Kind
which is an enum of freevar, cellvar, implicit_global, and implicit_local. Not yet populated. (TODO: a second pass over the scope (or the ast?) will observe theMARKED_GLOBAL
andMARKED_NONLOCAL
flags to populate this field. When that's added, we'll uncomment the field.)IS_DEFINED
andIS_USED
fields are correctly set and/or merged:add_or_update_symbol
will merge the flag arguments.x = foo
, the variablefoo
is considered used but not defined.from bar import foo
, the variablefoo
is considered defined but not used.