-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[red-knot] Add some narrowing for assignment expressions #17448
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] Add some narrowing for assignment expressions #17448
Conversation
|
There is still more to cover regarding named expressions. Such as: def f() -> bool: ...
if x := f():
reveal_type(x) # revealed: Literal[True]
else:
reveal_type(x) # revealed: Literal[False] |
|
|
mypy_primer looks good |
carljm
left a comment
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.
Looks really good, thank you!
There is still more to cover regarding named expressions.
Not required if you don't have time, but it would be really cool if this PR could just establish full parity, since it should be generally true that anywhere we would narrow on a Name, we should also be able to narrow on a NamedExpr. (If we don't reach parity, then I wouldn't want to close the associated issue yet.) And it doesn't seem like we are very far from that? It looks like a NamedExpr version of evaluate_name_expr (to intersect with AlwaysFalsy or AlwaysTruthy) would just be like five or six lines?
|
Okay, if you think I should do that in this PR, then I'll get that done |
…emt expression narrowing
|
Im not sure what else i need to cover |
carljm
left a comment
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.
Looks to me like you got everything! Thank you!!
|
I also re-checked the updated ecosystem results and they look good. The new errors are not a regression, they are just cases where other missing features mean there is still a (different) error on the same line that previously had an error. |
* main: [red-knot] class bases are not affected by __future__.annotations (#17456) [red-knot] Add support for overloaded functions (#17366) [`pyupgrade`] Add fix safety section to docs (`UP036`) (#17444) [red-knot] more type-narrowing in match statements (#17302) [red-knot] Add some narrowing for assignment expressions (#17448) [red-knot] Understand `typing.Protocol` and `typing_extensions.Protocol` as equivalent (#17446) Server: Use `min` instead of `max` to limit the number of threads (#17421)
* main: (123 commits) [red-knot] Handle explicit class specialization in type expressions (#17434) [red-knot] allow assignment expression in call compare narrowing (#17461) [red-knot] fix building unions with literals and AlwaysTruthy/AlwaysFalsy (#17451) [red-knot] Type narrowing for assertions (take 2) (#17345) [red-knot] class bases are not affected by __future__.annotations (#17456) [red-knot] Add support for overloaded functions (#17366) [`pyupgrade`] Add fix safety section to docs (`UP036`) (#17444) [red-knot] more type-narrowing in match statements (#17302) [red-knot] Add some narrowing for assignment expressions (#17448) [red-knot] Understand `typing.Protocol` and `typing_extensions.Protocol` as equivalent (#17446) Server: Use `min` instead of `max` to limit the number of threads (#17421) [red-knot] Detect version-related syntax errors (#16379) [`pyflakes`] Add fix safety section (`F841`) (#17410) [red-knot] Add `KnownFunction` variants for `is_protocol`, `get_protocol_members` and `runtime_checkable` (#17450) Bump 0.11.6 (#17449) Auto generate `visit_source_order` (#17180) [red-knot] Initial tests for protocols (#17436) [red-knot] Dataclasses: synthesize `__init__` with proper signature (#17428) [red-knot] Dataclasses: support `order=True` (#17406) [red-knot] Super-basic generic inference at call sites (#17301) ...
Summary
Fixes #14866
Fixes #17437
Test Plan
Update mdtests in
narrow/