Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/copyreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5283,10 +5283,12 @@ class Node(Generic[T]): ...
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix copying of :class:`typing.Union` objects containing objects that do not
support the ``|`` operator.
Loading