summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2021-04-11 03:00:05 (GMT)
committerGitHub <noreply@github.com>2021-04-11 03:00:05 (GMT)
commit9045919bfa820379a66ea67219f79ef6d9ecab49 (patch)
tree7762f15b2d875b36ffc84a2e98ff761e6267cd6d /Lib/test
parent522433601a5c64603dab3d733f41a5db39d237eb (diff)
downloadcpython-9045919bfa820379a66ea67219f79ef6d9ecab49.zip
cpython-9045919bfa820379a66ea67219f79ef6d9ecab49.tar.gz
cpython-9045919bfa820379a66ea67219f79ef6d9ecab49.tar.bz2
bpo-43772: Fix TypeVar.__ror__ (GH-25339)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 7183686..82c517a 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -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])