8000 update copyreg from CPython 3.12.3 · RustPython/RustPython@1333688 · GitHub
[go: up one dir, main page]

Skip to content
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 1333688

Browse files
CPython Developersyouknowone
CPython Developers
authored andcommitted
update copyreg from CPython 3.12.3
1 parent 17852b7 commit 1333688

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Lib/copyreg.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ def constructor(object):
2525

2626
# Example: provide pickling support for complex numbers.
2727

28-
try:
29-
complex
30-
except NameError:
31-
pass
32-
else:
28+
def pickle_complex(c):
29+
return complex, (c.real, c.imag)
3330

34-
def pickle_complex(c):
35-
return complex, (c.real, c.imag)
31+
pickle(complex, pickle_complex, complex)
3632

37-
pickle(complex, pickle_complex, complex)
33+
def pickle_union(obj):
34+
import functools, operator
35+
return functools.reduce, (operator.or_, obj.__args__)
36+
37+
pickle(type(int | str), pickle_union)
3838

3939
# Support for pickling new-style objects
4040

@@ -48,6 +48,7 @@ def _reconstructor(cls, base, state):
4848
return obj
4949

5050
_HEAPTYPE = 1<<9
51+
_new_type = type(int.__new__)
5152

5253
# Python code for object.__reduce_ex__ for protocols 0 and 1
5354

@@ -57,6 +58,9 @@ def _reduce_ex(self, proto):
5758
for base in cls.__mro__:
5859
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
5960
break
61+
new = base.__new__
62+
if isinstance(new, _new_type) and new.__self__ is base:
63+
break
6064
else:
6165
base = object # not really reachable
6266
if base is object:
@@ -79,6 +83,10 @@ def _reduce_ex(self, proto):
7983
except AttributeError:
8084
dict = None
8185
else:
86+
if (type(self).__getstate__ is object.__getstate__ and
87+
getattr(self, "__slots__", None)):
88+
raise TypeError("a class that defines __slots__ without "
89+
"defining __getstate__ cannot be pickled")
8290
dict = getstate()
8391
if dict:
8492
return _reconstructor, args, dict

0 commit comments

Comments
 (0)
0