Skip to content

Conversation

carljm
Copy link
Contributor

@carljm carljm commented Aug 25, 2025

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.)

@carljm carljm requested a review from AlexWaygood as a code owner August 25, 2025 17:47
@carljm carljm added the ty Multi-file analysis & type inference label Aug 25, 2025
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@carljm carljm merged commit 33c5f6f into main Aug 25, 2025
39 checks passed
@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
## 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.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants