Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 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]]
Union['T', int], List['T'], typing.Mapping['T', int],
Union[b"x", b"y"]]
for t in things + [Any]:
self.assertEqual(t, copy(t))
self.assertEqual(t, deepcopy(t))
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