mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-43772: Fix TypeVar.__ror__ (GH-25339)
This commit is contained in:
parent
522433601a
commit
9045919bfa
3 changed files with 13 additions and 2 deletions
|
@ -186,6 +186,16 @@ class TypeVarTests(BaseTestCase):
|
|||
self.assertEqual(Union[X, int].__parameters__, (X,))
|
||||
self.assertIs(Union[X, int].__origin__, Union)
|
||||
|
||||
def test_or(self):
|
||||
X = TypeVar('X')
|
||||
# use a string because str doesn't implement
|
||||
# __or__/__ror__ itself
|
||||
self.assertEqual(X | "x", Union[X, "x"])
|
||||
self.assertEqual("x" | X, Union["x", X])
|
||||
# make sure the order is correct
|
||||
self.assertEqual(get_args(X | "x"), (X, ForwardRef("x")))
|
||||
self.assertEqual(get_args("x" | X), (ForwardRef("x"), X))
|
||||
|
||||
def test_union_constrained(self):
|
||||
A = TypeVar('A', str, bytes)
|
||||
self.assertNotEqual(Union[A, str], Union[A])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue