-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-43772: fix TypeVar.__ror__ #25339
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.
Thanks! I just have a comment about the tests
self.assertEqual(X | "x", Union[X, "x"]) | ||
self.assertEqual("x" | X, Union["x", X]) |
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.
I don't think these are testing for what Larry meant, Union comparisons are order independent, so
>>> T | "x" == "x" | T
True
>>> T | "x" == Union["x" | T]
True
And the current test should pass even without the patch.
What he meant is that the repr
is order dependent, so the test should be something like:
self.assertEqual(X | "x", Union[X, "x"]) | |
self.assertEqual("x" | X, Union["x", X]) | |
self.assertEqual(repr(X | int), "typing.Union[~X, int]") | |
self.assertEqual(repr(int | X), "typing.Union[int, ~X]") |
Which currently fails without the patch:
>>> repr(T | int)
"typing.Union[~T, int]"
>>> repr(int | T)
"typing.Union[int, ~T]"
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.
Good point, I should have written the test first to make sure I was actually fixing anything.
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.
Made it use get_args()
to test though, which feels cleaner than testing the repr()
directly.
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.
Yeah I think that works :). The __repr__
is dependent on __args__
after all.
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.
LGTM.
A very simple change.
https://bugs.python.org/issue43772