-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Introduce temporary named expressions for match
subjects
#18446
base: master
Are you sure you want to change the base?
Introduce temporary named expressions for match
subjects
#18446
Conversation
This comment has been minimized.
This comment has been minimized.
Whoa, I expected this to produce at least a couple of unused ignore diagnostics, but apparently pattern matching isn't very popular in wild... |
…ic-named-expr-in-match
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
…ic-named-expr-in-match
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ic-named-expr-in-match
This comment has been minimized.
This comment has been minimized.
…ic-named-expr-in-match
This interferes with recently added narrowing by item/attribute (aka discriminated union, |
This comment has been minimized.
This comment has been minimized.
To support narrowing the subject and its "dependencies" simultaneously, I propose to just push the narrowed type of subject to typemap as the type of its original form, allowing for any inference on it. |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #18440. Fixes #17230.
#16503 did this specifically for
CallExpr
, but that isn't the only kind of such statements. I propose to expand this for more general expressions and believe that a blacklist is more reasonable here: we do not want to introduce a temporary name only for certain expressions that either are already named or can be used to infer contained variables (inline tuple/list/dict/set literals).Writing logic to generate a name for every other kind of expression would be quite cumbersome - I circumvent this by using a simple counter to generate unique names on demand.