ruff
16cc9322 - [ty] Fix nested global and nonlocal lookups through forwarding scopes (#24279)

Commit
18 days ago
[ty] Fix nested global and nonlocal lookups through forwarding scopes (#24279) ## Summary Given the motivating example: ```python PULL_SUMS: "list[float]" = [] def bandit(foo: int) -> None: global PULL_SUMS if foo == 0: # commenting this out fixes it PULL_SUMS = [] return def bar(arm): return PULL_SUMS[arm] ``` Before this change, in `bar`, we'd first look at the `bandit` scope, but because `bandit` had `PULL_SUMS = []`, we stopped walking outward to the module scope, and never saw the top-level `PULL_SUMS: "list[float]" = []`. Now, if the binding in the scope is just an unbound placeholder for a `nonlocal` or `global`, we keep walking outwards. Closes https://github.com/astral-sh/ty/issues/3157.
Author
Parents
Loading