mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 13:30:49 -05:00
Summary --------- PEP 695 Generics introduce a scope inside a class statement's arguments and keywords. ``` class C[T](A[T]): # the T in A[T] is not from the global scope but from a type-param-specfic scope ... ``` When doing inference on the class bases, we currently have been doing base class expression lookups in the global scope. Not an issue without generics (since a scope is only created when generics are present). This change instead makes sure to stop the global scope inference from going into expressions within this sub-scope. Since there is a separate scope, `check_file` and friends will trigger inference on these expressions still. Another change as a part of this is making sure that `ClassType` looks up its bases in the right scope. Test Plan ---------- `cargo test --package red_knot_python_semantic generics` will run the markdown test that previously would panic due to scope lookup issues --------- Co-authored-by: Micha Reiser <micha@reiser.io> Co-authored-by: Carl Meyer <carl@astral.sh>