bpo-28556: Don't simplify unions at runtime (GH-6841) · python/cpython@f65e31f (original) (raw)
`@@ -253,10 +253,11 @@ def test_union_any(self):
`
253
253
`def test_union_object(self):
`
254
254
`u = Union[object]
`
255
255
`self.assertEqual(u, object)
`
256
``
`-
u = Union[int, object]
`
257
``
`-
self.assertEqual(u, object)
`
258
``
`-
u = Union[object, int]
`
259
``
`-
self.assertEqual(u, object)
`
``
256
`+
u1 = Union[int, object]
`
``
257
`+
u2 = Union[object, int]
`
``
258
`+
self.assertEqual(u1, u2)
`
``
259
`+
self.assertNotEqual(u1, object)
`
``
260
`+
self.assertNotEqual(u2, object)
`
260
261
``
261
262
`def test_unordered(self):
`
262
263
`u1 = Union[int, float]
`
`@@ -267,13 +268,11 @@ def test_single_class_disappears(self):
`
267
268
`t = Union[Employee]
`
268
269
`self.assertIs(t, Employee)
`
269
270
``
270
``
`-
def test_base_class_disappears(self):
`
271
``
`-
u = Union[Employee, Manager, int]
`
272
``
`-
self.assertEqual(u, Union[int, Employee])
`
273
``
`-
u = Union[Manager, int, Employee]
`
274
``
`-
self.assertEqual(u, Union[int, Employee])
`
``
271
`+
def test_base_class_kept(self):
`
275
272
`u = Union[Employee, Manager]
`
276
``
`-
self.assertIs(u, Employee)
`
``
273
`+
self.assertNotEqual(u, Employee)
`
``
274
`+
self.assertIn(Employee, u.args)
`
``
275
`+
self.assertIn(Manager, u.args)
`
277
276
``
278
277
`def test_union_union(self):
`
279
278
`u = Union[int, float]
`
`@@ -317,7 +316,8 @@ def test_cannot_instantiate(self):
`
317
316
`def test_union_generalization(self):
`
318
317
`self.assertFalse(Union[str, typing.Iterable[int]] == str)
`
319
318
`self.assertFalse(Union[str, typing.Iterable[int]] == typing.Iterable[int])
`
320
``
`-
self.assertTrue(Union[str, typing.Iterable] == typing.Iterable)
`
``
319
`+
self.assertIn(str, Union[str, typing.Iterable[int]].args)
`
``
320
`+
self.assertIn(typing.Iterable[int], Union[str, typing.Iterable[int]].args)
`
321
321
``
322
322
`def test_union_compare_other(self):
`
323
323
`self.assertNotEqual(Union, object)
`
`@@ -917,7 +917,7 @@ def test_extended_generic_rules_eq(self):
`
917
917
`self.assertEqual(Union[T, U][int, Union[int, str]], Union[int, str])
`
918
918
`class Base: ...
`
919
919
`class Derived(Base): ...
`
920
``
`-
self.assertEqual(Union[T, Base][Derived], Base)
`
``
920
`+
self.assertEqual(Union[T, Base][Union[Base, Derived]], Union[Base, Derived])
`
921
921
`with self.assertRaises(TypeError):
`
922
922
`Union[T, int][1]
`
923
923
``