-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Red Knot - Add symbol flags (#11134)
* Adds `Symbol.flag` bitfield. Populates it from (the three renamed) `add_or_update_symbol*` methods. * Currently there are these flags supported: * `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 and `IS_DEFINED` would require two separate appearances of a variable in the same scope-- one def and one use.) * `MARKED_GLOBAL` and `MARKED_NONLOCAL` are **not yet implemented**. (*TODO: While traversing, if you find these declarations, add these flags to the variable.*) * Adds `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 the `MARKED_GLOBAL` and `MARKED_NONLOCAL` flags to populate this field. When that's added, we'll uncomment the field.*) * Adds a few tests that the `IS_DEFINED` and `IS_USED` fields are correctly set and/or merged: * Unit test that subsequent calls to `add_or_update_symbol` will merge the flag arguments. * Unit test that in the statement `x = foo`, the variable `foo` is considered used but not defined. * Unit test that in the statement `from bar import foo`, the variable `foo` is considered defined but not used. --------- Co-authored-by: Carl Meyer <carl@astral.sh>
- Loading branch information
Showing
1 changed file
with
104 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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