Skip to content
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] Infer generator expressions #13129

Closed
wants to merge 4 commits into from

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Aug 27, 2024

Adds a Generator type and infers the type of a generator expression as Generator[T, None, None] where T is the inferred type of the first comprehension.

Related to #12701.

@dylwil3
Copy link
Collaborator Author

dylwil3 commented Aug 27, 2024

This is my first one of these, so apologies if I'm way off!

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@carljm carljm added the red-knot Multi-file analysis & type inference label Aug 27, 2024
@carljm
Copy link
Contributor

carljm commented Aug 27, 2024

Hey, thanks so much for the PR! So I should have added more color to #12701 to clarify some of these better; this is an example of one where we're kinda blocked on adding support for generics in order to do this correctly. The generator type should be derived from its definition in typeshed rather than added as a special case in the Type enum. And understanding its definition in typeshed requires that we understand type variables and generic classes, which we don't have. Sorry this wasn't clear in the issue, I've updated the text of the issue now to mark the ones blocked on this!

Going to close this since I think pretty much everything here would look different with the typeshed/generics approach, sorry about that! If you're interested in tackling an open expression kind, there are gaps in our unary/binary expression support, or for something a bit more complex, lambda expressions might be interesting. @chriskrycho is currently working on call expression inference, which will unlock a bunch more expression kinds where we should be resolving them as dunder method calls. Feel free to ping us on Discord or in the issue if you want to get a bit of direction before starting work on an issue!

@carljm carljm closed this Aug 27, 2024
@dylwil3 dylwil3 deleted the infer-generator branch August 28, 2024 00:57
@dylwil3
Copy link
Collaborator Author

dylwil3 commented Aug 28, 2024

Not a problem! Sorry for spamming the PRs 😅 I'll coordinate on the issue/Discord before taking another stab. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants