-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
isinstance(x, (T1, T2)) won't narrow the type of x when NamedTuple is involved. #1914
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
Labels
Comments
This might be related to #1691. |
JukkaL
added a commit
that referenced
this issue
Mar 29, 2017
The main change is that unions containing Any are no longer simplified to just Any. Also union simplification now has a deterministic result unlike previously, when result could depend on the order of items in a union (this is true modulo remaining bugs). This required changes in various other places to keep the existing semantics, and resulted in some fixes to existing test cases. I also had to fix some tangentially related minor bugs that were triggered by the other changes. We generally don't have fully constructed TypeInfos so we can't do proper union simplification during semantic analysis. Just implement simple-minded simplification that deals with the cases we care about. Fixes #2978. Fixes #1914.
JukkaL
added a commit
that referenced
this issue
Mar 30, 2017
The main change is that unions containing Any are no longer simplified to just Any. Also union simplification now has a deterministic result unlike previously, when result could depend on the order of items in a union (this is true modulo remaining bugs). This required changes in various other places to keep the existing semantics, and resulted in some fixes to existing test cases. I also had to fix some tangentially related minor bugs that were triggered by the other changes. We generally don't have fully constructed TypeInfos so we can't do proper union simplification during semantic analysis. Just implement simple-minded simplification that deals with the cases we care about. Fixes #2978. Fixes #1914.
ilevkivskyi
pushed a commit
that referenced
this issue
Apr 4, 2017
* Fixes to union simplification, isinstance and more (#3025) The main change is that unions containing Any are no longer simplified to just Any. Also union simplification now has a deterministic result unlike previously, when result could depend on the order of items in a union (this is true modulo remaining bugs). This required changes in various other places to keep the existing semantics, and resulted in some fixes to existing test cases. I also had to fix some tangentially related minor bugs that were triggered by the other changes. We generally don't have fully constructed TypeInfos so we can't do proper union simplification during semantic analysis. Just implement simple-minded simplification that deals with the cases we care about. Fixes #2978. Fixes #1914. * Fix strict optional and partial type special case and fix test * Fix lint * Make is_subtype and is_proper_subtype do promotion the same way Fixes #1850. * Drop reference to ErrorType (recently expunged) * Fix merge mistake * Fix another merge mistake * Update based on review * Add test case * Fix redundant TODO due to copy paste
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Test case:
This fails with:
The error happens only when NamedTuple is involved. Otherwise the type of
a
is correctly narrowed toUnion[B, C]
inside the branch.cc #1328
The text was updated successfully, but these errors were encountered: