ruff
c391c8b6 - Red Knot - Add symbol flags (#11134)

Commit
1 year ago
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>
Author
Parents
Loading