mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Add a comment about how some built-in types should grow a
__getnewargs__ method.
This commit is contained in:
parent
b26a97aa50
commit
4e2491dbb1
1 changed files with 3 additions and 1 deletions
|
@ -368,13 +368,15 @@ class Pickler:
|
|||
|
||||
def save_newobj(self, obj):
|
||||
# Save a new-style class instance, using protocol 2.
|
||||
# XXX Much of this is still experimental.
|
||||
# XXX This is still experimental.
|
||||
assert self.proto >= 2 # This only works for protocol 2
|
||||
t = type(obj)
|
||||
getnewargs = getattr(obj, "__getnewargs__", None)
|
||||
if getnewargs:
|
||||
args = getnewargs() # This bette not reference obj
|
||||
else:
|
||||
# XXX These types should each grow a __getnewargs__
|
||||
# implementation so this special-casing is unnecessary.
|
||||
for cls in int, long, float, complex, str, UnicodeType, tuple:
|
||||
if cls and isinstance(obj, cls):
|
||||
args = (cls(obj),)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue