-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-28556: Don't simplify unions at runtime #6841
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
Conversation
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.
The change itself looks find to me, but its not clear that changing this is the right thing to do. As a general note we're removing old explicit logic and tests rather than just fixing a bug. I didn't notice any discussion of the issue on the mailing list or otherwise. Feel free to direct me if I missed it.
Some people see this as a bug, see example in the issue linked above. Also this code was a bug magnet because it needs to use |
@gvanrossum Sorry for being annoying, but if we want to get this in 3.7 we only have time until Monday. Could you please briefly take a look at this PR? |
No worries. I'll try to review later today. |
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.
A few nits about tests; the substance of the code LGTM. (Nice that it was such a clear separate bit of code. :-)
self.assertEqual(u, object) | ||
u1 = Union[int, object] | ||
u2 = Union[object, int] | ||
self.assertEqual(u1, u2) |
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.
Maybe also assert that it isn't object
?
Lib/test/test_typing.py
Outdated
u = Union[Employee, Manager] | ||
self.assertIs(u, Employee) | ||
self.assertIsNot(u, Employee) |
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.
Can you check that Employee and Manager are both members of the union?
@@ -317,7 +312,6 @@ def test_cannot_instantiate(self): | |||
def test_union_generalization(self): | |||
self.assertFalse(Union[str, typing.Iterable[int]] == str) | |||
self.assertFalse(Union[str, typing.Iterable[int]] == typing.Iterable[int]) | |||
self.assertTrue(Union[str, typing.Iterable] == typing.Iterable) |
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.
How about a more positive test of the expected members?
Lib/typing.py
Outdated
@@ -203,7 +203,7 @@ def _check_generic(cls, parameters): | |||
|
|||
def _remove_dups_flatten(parameters): | |||
"""An internal helper for Union creation and substitution: flatten Union's |
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.
Union's -> Unions
@gvanrossum Thanks for review! I addressed all comments, plus I think there is one important point to add: this change breaks semantics of |
Sorry, the tenses are confusing. Is the problem with List[Union[Manager, Employee]] returning List[Employee] happening with this version of the PR or would that happen if you "tweaked" Honestly given that we don't simplify unions I think it's right that Union[Manager, Employee] != Employee. |
Also I think this requires a news item. |
OK, This is what happens with this PR, the problem I described would will appear only if I will tweak
OK, I will add it. |
asyncio failures are unrelated/flakes. |
I will close and re-open to trigger AppVeyor. |
Restarting AppVeyor again... |
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.
You have to merge this manually because the VSTS tests always fail (they are non-blocking, but Miss Islington doesn't know).
OK, I see. Will do this now. |
Thanks @ilevkivskyi for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
(cherry picked from commit f65e31f) Co-authored-by: Ivan Levkivskyi <[email protected]>
GH-6979 is a backport of this pull request to the 3.7 branch. |
(cherry picked from commit f65e31f) Co-authored-by: Ivan Levkivskyi <[email protected]>
Fixes python/typing#536
cc @gvanrossum
https://bugs.python.org/issue28556