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.
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
[red-knot] Resolve references in eager nested scopes eagerly #16079
[red-knot] Resolve references in eager nested scopes eagerly #16079
Changes from 35 commits
9d101d6
2789cd0
23ed82d
5f566cd
6ea3655
1e5ae86
16b63ba
f4904b1
b8ffa78
e5eaab9
a3ea477
4cd5ae0
0c394ab
df91210
06f76ae
cf78c49
54efbbe
7e0ef53
be8f9eb
908d3e2
a63c6e6
5db470e
28d6513
f72c268
f647032
4eb38fd
de73d08
dfb7384
95a6bb8
e13ac91
71194ba
3b5277e
fc93843
4556f4d
03ce733
fc6c009
40d5be2
3cf2308
8a2449f
576f54d
c344871
260756b
b24cf07
4931bd4
1a7cbe8
a55a01a
d76d362
c65011f
889a64b
888ba7b
cb22523
86a243c
f474b43
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I wonder if it might be good to explicitly include an example of a generator-expression scope that does not run eagerly? It might be good to document that yes, this causes some incorrect assumptions from us in some edge cases, but that this is a cost we accept because (as you say) generator expressions nearly always run eagerly in practice. One example might be something like this: we report the revealed type of
z
isLiteral[42]
:but at runtime, the
print()
call reveals that the runtime value ofz
can actually be 56 when the scope ofgen()
is actually evaluated:(Again, I'm not saying we should try to account for this -- generator expressions are almost always evaluated eagerly, and it would be hard to detect cases like this when they're not! Just suggesting we could add a test to explicitly document the shortcoming.)
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.
Done. I also added a test for how the "first iterable" is evaluated eagerly, even if the generator itself is not used immediately.
This example tells me that we'd want to handle generators the same as functions, if we ever start tracking where they're called as part of the public types work (#16079 (review)). After all, that's precisely the weirdness that's happening here — the generator includes a
__next__
method that might be called at any arbitrary place, just like thef
function in your linked comment might be called at any arbitrary place. If we start tracking that, we should use the same mechanism for both.