-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazily evaluate all PEP 695 type alias values #8033
Conversation
a33c0b7
to
7910ff5
Compare
@@ -0,0 +1,5 @@ | |||
"""Test lazy evaluation of type alias values.""" | |||
|
|||
type RecordCallback[R: Record] = Callable[[R], None] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Record
should be undefined, but Callable
should resolve.
from collections.abc import Callable | ||
|
||
from .foo import Record as Record1 | ||
from .bar import Record as Record2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these should be considered "used".
7910ff5
to
2998bc8
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! I was going to look into it but ya beat me to it (which is good because I would have been confused)
Summary
In #7968, I introduced a regression whereby we started to treat imports used only in type annotation bounds (with
__future__
annotations) as unused.The root of the issue is that I started using
visit_annotation
for these bounds. So we'd queue up the bound in the list of deferred type parameters, then when visiting, we'd further queue it up in the list of deferred type annotations... Which we'd then never visit, since deferred type annotations are visited before deferred type parameters.Anyway, the better solution here is to use a dedicated flag for these, since they have slightly different behavior than type annotations.
I've also fixed what I think is a bug whereby we previously failed to resolve
Callable
in:IIUC, the values in type aliases should be evaluated lazily, like type parameters.
Closes #8017.
Test Plan
cargo test