bpo-28556: Don't simplify unions at runtime (GH-6841) (GH-6979)

(cherry picked from commit f65e31fee3)

Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-05-18 16:27:14 -07:00 committed by Ivan Levkivskyi
parent abde17e663
commit 09ca5906b7
4 changed files with 21 additions and 45 deletions

View file

@ -253,10 +253,11 @@ class UnionTests(BaseTestCase):
def test_union_object(self):
u = Union[object]
self.assertEqual(u, object)
u = Union[int, object]
self.assertEqual(u, object)
u = Union[object, int]
self.assertEqual(u, object)
u1 = Union[int, object]
u2 = Union[object, int]
self.assertEqual(u1, u2)
self.assertNotEqual(u1, object)
self.assertNotEqual(u2, object)
def test_unordered(self):
u1 = Union[int, float]
@ -267,13 +268,11 @@ class UnionTests(BaseTestCase):
t = Union[Employee]
self.assertIs(t, Employee)
def test_base_class_disappears(self):
u = Union[Employee, Manager, int]
self.assertEqual(u, Union[int, Employee])
u = Union[Manager, int, Employee]
self.assertEqual(u, Union[int, Employee])
def test_base_class_kept(self):
u = Union[Employee, Manager]
self.assertIs(u, Employee)
self.assertNotEqual(u, Employee)
self.assertIn(Employee, u.__args__)
self.assertIn(Manager, u.__args__)
def test_union_union(self):
u = Union[int, float]
@ -317,7 +316,8 @@ class UnionTests(BaseTestCase):
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)
self.assertIn(str, Union[str, typing.Iterable[int]].__args__)
self.assertIn(typing.Iterable[int], Union[str, typing.Iterable[int]].__args__)
def test_union_compare_other(self):
self.assertNotEqual(Union, object)
@ -917,7 +917,7 @@ class GenericTests(BaseTestCase):
self.assertEqual(Union[T, U][int, Union[int, str]], Union[int, str])
class Base: ...
class Derived(Base): ...
self.assertEqual(Union[T, Base][Derived], Base)
self.assertEqual(Union[T, Base][Union[Base, Derived]], Union[Base, Derived])
with self.assertRaises(TypeError):
Union[T, int][1]