bpo-28556: Don't simplify unions at runtime#6841
Conversation
grimreaper
left a comment
There was a problem hiding this comment.
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. |
gvanrossum
left a comment
There was a problem hiding this comment.
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.
Maybe also assert that it isn't object?
Lib/test/test_typing.py
Outdated
| def test_base_class_kept(self): | ||
| u = Union[Employee, Manager] | ||
| self.assertIs(u, Employee) | ||
| self.assertIsNot(u, Employee) |
There was a problem hiding this comment.
Can you check that Employee and Manager are both members of the union?
| 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.
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 | |||
|
@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... |
gvanrossum
left a comment
There was a problem hiding this comment.
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 <levkivskyi@gmail.com>
|
GH-6979 is a backport of this pull request to the 3.7 branch. |
Fixes python/typing#536
cc @gvanrossum
https://bugs.python.org/issue28556