-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
"'field' in typed_dict_union" discrimination #13802
Comments
This has been discussed previously in various typing forums. (I can't find the threads currently, but perhaps someone else can find a pointer.) The problem here is that narrowing based on field discrimination within a With an from typing import TypedDict, final
@final
class A(TypedDict):
foo: int
@final
class B(TypedDict):
bar: int
def func(union: A | B):
if "foo" in union:
reveal_type(union) # A
else:
reveal_type(union) # B |
#7981 is probably the right mypy issue to track this |
Thanks for the pointer @hauntsaninja, indeed appears to be addressed in #13557. Happy to test once it makes its way into the next release. |
Only half the feature is implemented; want to take a shot at completing it? |
Feature
Similar to tagged unions, I wish an
in
check could discriminate the following:Similarly:
The text was updated successfully, but these errors were encountered: