mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
gh-132882: Fix copying of unions with members that do not support __or__ (#132883)
This commit is contained in:
parent
9f5994b94c
commit
e1c09fff05
3 changed files with 10 additions and 6 deletions
|
@ -31,8 +31,8 @@ def pickle_complex(c):
|
|||
pickle(complex, pickle_complex, complex)
|
||||
|
||||
def pickle_union(obj):
|
||||
import functools, operator
|
||||
return functools.reduce, (operator.or_, obj.__args__)
|
||||
import typing, operator
|
||||
return operator.getitem, (typing.Union, obj.__args__)
|
||||
|
||||
pickle(type(int | str), pickle_union)
|
||||
|
||||
|
|
|
@ -5283,10 +5283,12 @@ class GenericTests(BaseTestCase):
|
|||
Tuple[Any, Any], Node[T], Node[int], Node[Any], typing.Iterable[T],
|
||||
typing.Iterable[Any], typing.Iterable[int], typing.Dict[int, str],
|
||||
typing.Dict[T, Any], ClassVar[int], ClassVar[List[T]], Tuple['T', 'T'],
|
||||
Union['T', int], List['T'], typing.Mapping['T', int]]
|
||||
for t in things + [Any]:
|
||||
self.assertEqual(t, copy(t))
|
||||
self.assertEqual(t, deepcopy(t))
|
||||
Union['T', int], List['T'], typing.Mapping['T', int],
|
||||
Union[b"x", b"y"], Any]
|
||||
for t in things:
|
||||
with self.subTest(thing=t):
|
||||
self.assertEqual(t, copy(t))
|
||||
self.assertEqual(t, deepcopy(t))
|
||||
|
||||
def test_immutability_by_copy_and_pickle(self):
|
||||
# Special forms like Union, Any, etc., generic aliases to containers like List,
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix copying of :class:`typing.Union` objects containing objects that do not
|
||||
support the ``|`` operator.
|
Loading…
Add table
Add a link
Reference in a new issue