[ty] don't mark entire type-alias scopes as Deferred by carljm · Pull Request #20086 · astral-sh/ruff (original) (raw)

@carljm

@carljm carljm added the ty

Multi-file analysis & type inference

label

Aug 25, 2025

AlexWaygood

@carljm carljm deleted the cjm/typealias-deferred branch

August 25, 2025 18:32

second-ed pushed a commit to second-ed/ruff that referenced this pull request

Sep 9, 2025

@carljm @second-ed

Summary

This has been here for awhile (since our initial PEP 695 type alias support) but isn't really correct. The right-hand-side of a PEP 695 type alias is a distinct scope, and we don't mark it as an "eager" nested scope, so it automatically gets "deferred" resolution of names from outer scopes (just like a nested function). Thus it's redundant/unnecessary for us to use DeferredExpressionState::Deferred for resolving that RHS expression -- that's for deferring resolution of individual names within a scope. Using it here causes us to wrongly ignore applicable outer-scope narrowing.

Test Plan

Added mdtest that failed before this PR (the second snippet -- the first snippet always passed.)

This file contains hidden or 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

[ Show hidden characters]({{ revealButtonHref }})