Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9f5994b commit e1c09ffCopy full SHA for e1c09ff
3 files changed
Lib/copyreg.py
@@ -31,8 +31,8 @@ def pickle_complex(c):
31
pickle(complex, pickle_complex, complex)
32
33
def pickle_union(obj):
34
- import functools, operator
35
- return functools.reduce, (operator.or_, obj.__args__)
+ import typing, operator
+ return operator.getitem, (typing.Union, obj.__args__)
36
37
pickle(type(int | str), pickle_union)
38
Lib/test/test_typing.py
@@ -5283,10 +5283,12 @@ class Node(Generic[T]): ...
5283
Tuple[Any, Any], Node[T], Node[int], Node[Any], typing.Iterable[T],
5284
typing.Iterable[Any], typing.Iterable[int], typing.Dict[int, str],
5285
typing.Dict[T, Any], ClassVar[int], ClassVar[List[T]], Tuple['T', 'T'],
5286
- Union['T', int], List['T'], typing.Mapping['T', int]]
5287
- for t in things + [Any]:
5288
- self.assertEqual(t, copy(t))
5289
- 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):
5290
+ self.assertEqual(t, copy(t))
5291
+ self.assertEqual(t, deepcopy(t))
5292
5293
def test_immutability_by_copy_and_pickle(self):
5294
# Special forms like Union, Any, etc., generic aliases to containers like List,
Misc/NEWS.d/next/Library/2025-04-24-09-10-04.gh-issue-132882.6zoyp5.rst
@@ -0,0 +1,2 @@
1
+Fix copying of :class:`typing.Union` objects containing objects that do not
2
+support the ``|`` operator.
0 commit comments