-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
pickle documentation says that unpickling may not call __new__ #71822
Comments
A note just below object.__setstate__() documentation I believe that note about not calling __new__() was relevant in python2. I could not find case in python3 in which __new__() would not be called. And __init__() is not called anyway, as far as I understand (unless explicitly by __setstate__() or something). Python 3.6.0a3+ (default:da9898e7e90d, Jul 27 2016, 19:51:12)
[GCC 4.9.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class C:
... def __getstate__(self): return {'foo' : self.foo}
... def __setstate__(self, state): self.foo = state['foo']
... def __new__(cls):
... print('__new__ is called'); return super().__new__(cls)
... def __init__(self):
... print('__init__ is called'); self.foo = None; super().__init__()
...
>>> c = C(); c.foo = 'bar'
__new__ is called
__init__ is called
>>> import pickle
>>> c2 = pickle.loads(pickle.dumps(c))
__new__ is called
>>> c2.foo
'bar' |
There is still an mistake in the document. I sent a pr to fix it. |
The problem is fixed, issue can be closed. |
Ping (to close the issue). |
__new__
not being called. #19269__new__
not being called. (GH-19269) #19585__new__
not being called. (GH-19269) #19586Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: