astral-sh/ruff

[red-knot] fix deferred annotations referencing other scopes

carljm opened this issue · 0 comments

Our current handling for resolving deferred annotations uses the inferred types of symbols as they exist at the end of the current scope (rather than the current point in control flow of the current scope), which is correct (or at least the most reasonable option) since their resolution is deferred.

But it currently does this by piggy-backing on the same logic we use for e.g. import resolution, where the name must exist in the scope's namespace, there's no fallback to other scopes. So we can't resolve a deferred annotation that's a builtin, or a global or nonlocal referred to from a nested scope. This should be fixed.