Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1c09ff

Browse filesBrowse files
gh-132882: Fix copying of unions with members that do not support __or__ (#132883)
1 parent 9f5994b commit e1c09ff
Copy full SHA for e1c09ff

File tree

Expand file treeCollapse file tree

3 files changed

+10
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-6
lines changed

‎Lib/copyreg.py

Copy file name to clipboardExpand all lines: Lib/copyreg.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def pickle_complex(c):
3131
pickle(complex, pickle_complex, complex)
3232

3333
def pickle_union(obj):
34-
import functools, operator
35-
return functools.reduce, (operator.or_, obj.__args__)
34+
import typing, operator
35+
return operator.getitem, (typing.Union, obj.__args__)
3636

3737
pickle(type(int | str), pickle_union)
3838

‎Lib/test/test_typing.py

Copy file name to clipboardExpand all lines: Lib/test/test_typing.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5283,10 +5283,12 @@ class Node(Generic[T]): ...
52835283
Tuple[Any, Any], Node[T], Node[int], Node[Any], typing.Iterable[T],
52845284
typing.Iterable[Any], typing.Iterable[int], typing.Dict[int, str],
52855285
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))
5286+
Union['T', int], List['T'], typing.Mapping['T', int],
5287+
Union[b"x", b"y"], Any]
5288+
for t in things:
5289+
with self.subTest(thing=t):
5290+
self.assertEqual(t, copy(t))
5291+
self.assertEqual(t, deepcopy(t))
52905292

52915293
def test_immutability_by_copy_and_pickle(self):
52925294
# Special forms like Union, Any, etc., generic aliases to containers like List,
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix copying of :class:`typing.Union` objects containing objects that do not
2+
support the ``|`` operator.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.