8000 object.__getstate__ by youknowone · Pull Request #5342 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

object.__getstate__ #5342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 22, 2024
Merged
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
Prev Previous commit
update copyreg from CPython 3.12.3
  • Loading branch information
CPython Developers authored and youknowone committed Jun 22, 2024
commit 1333688a4eae08cc7e0dc04b6aba47ebffe27f93
24 changes: 16 additions & 8 deletions Lib/copyreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def constructor(object):

# Example: provide pickling support for complex numbers.

try:
complex
except NameError:
pass
else:
def pickle_complex(c):
return complex, (c.real, c.imag)

def pickle_complex(c):
return complex, (c.real, c.imag)
pickle(complex, pickle_complex, complex)

pickle(complex, pickle_complex, complex)
def pickle_union(obj):
import functools, operator
return functools.reduce, (operator.or_, obj.__args__)

pickle(type(int | str), pickle_union)

# Support for pickling new-style objects

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

_HEAPTYPE = 1<<9
_new_type = type(int.__new__)

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

Expand All @@ -57,6 +58,9 @@ def _reduce_ex(self, proto):
for base in cls.__mro__:
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
break
new = base.__new__
if isinstance(new, _new_type) and new.__self__ is base:
break
else:
base = object # not really reachable
if base is object:
Expand All @@ -79,6 +83,10 @@ def _reduce_ex(self, proto):
except AttributeError:
dict = None
else:
if (type(self).__getstate__ is object.__getstate__ and
getattr(self, "__slots__", None)):
raise TypeError("a class that defines __slots__ without "
"defining __getstate__ cannot be pickled")
dict = getstate()
if dict:
return _reconstructor, args, dict
Expand Down
Loading
0