Lazily evaluate all PEP 695 type alias values#8033
Merged
charliermarsh merged 1 commit intomainfrom Oct 18, 2023
Merged
Conversation
a33c0b7 to
7910ff5
Compare
charliermarsh
commented
Oct 18, 2023
| @@ -0,0 +1,5 @@ | |||
| """Test lazy evaluation of type alias values.""" | |||
|
|
|||
| type RecordCallback[R: Record] = Callable[[R], None] | |||
Member
Author
There was a problem hiding this comment.
Record should be undefined, but Callable should resolve.
charliermarsh
commented
Oct 18, 2023
| from collections.abc import Callable | ||
|
|
||
| from .foo import Record as Record1 | ||
| from .bar import Record as Record2 |
Member
Author
There was a problem hiding this comment.
Both of these should be considered "used".
7910ff5 to
2998bc8
Compare
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
zanieb
approved these changes
Oct 18, 2023
Member
zanieb
left a comment
There was a problem hiding this comment.
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)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_annotationfor 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
Callablein:IIUC, the values in type aliases should be evaluated lazily, like type parameters.
Closes #8017.
Test Plan
cargo test