Issue 27635: pickle documentation says that unpickling may not call new (original) (raw)
Created on 2016-07-27 17:07 by july, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Pull Requests | |||
---|---|---|---|
URL | Status | Linked | Edit |
PR 19269 | merged | furkanonder,2020-04-01 00:17 | |
PR 19585 | merged | miss-islington,2020-04-18 18:09 | |
PR 19586 | merged | miss-islington,2020-04-18 18:09 |
Messages (7) | ||
---|---|---|
msg271465 - (view) | Author: July Tikhonov (july) * | Date: 2016-07-27 17:07 |
A note just below object.__setstate__() documentation https://docs.python.org/3.6/library/pickle.html#object.__setstate__ says that """ … the type should implement __getnewargs__() or __getnewargs_ex__() to establish such an invariant; otherwise, neither __new__() nor __init__() will be called. """ 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' | ||
msg365442 - (view) | Author: Furkan Onder (furkanonder) * | Date: 2020-04-01 00:21 |
There is still an mistake in the document. I sent a pr to fix it. | ||
msg366730 - (view) | Author: miss-islington (miss-islington) | Date: 2020-04-18 18:09 |
New changeset 482259d0dcf27714a84cf56b93977320bea7e093 by Furkan Önder in branch 'master': bpo-27635: Fix pickle documentation about `__new__` not being called. (GH-19269) https://github.com/python/cpython/commit/482259d0dcf27714a84cf56b93977320bea7e093 | ||
msg366731 - (view) | Author: miss-islington (miss-islington) | Date: 2020-04-18 18:14 |
New changeset 0abb548cc7b239fbe426ca9e00968130e53ffc98 by Miss Islington (bot) in branch '3.7': bpo-27635: Fix pickle documentation about `__new__` not being called. (GH-19269) https://github.com/python/cpython/commit/0abb548cc7b239fbe426ca9e00968130e53ffc98 | ||
msg366732 - (view) | Author: miss-islington (miss-islington) | Date: 2020-04-18 18:14 |
New changeset 020f2aaaea95aef6f54ab31488926ed76017e41a by Miss Islington (bot) in branch '3.8': bpo-27635: Fix pickle documentation about `__new__` not being called. (GH-19269) https://github.com/python/cpython/commit/020f2aaaea95aef6f54ab31488926ed76017e41a | ||
msg366950 - (view) | Author: Furkan Onder (furkanonder) * | Date: 2020-04-21 23:12 |
The problem is fixed, issue can be closed. | ||
msg378451 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2020-10-11 19:32 |
Ping (to close the issue). |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:34 | admin | set | github: 71822 |
2020-10-11 20:22:32 | alexandre.vassalotti | set | status: open -> closedstage: patch review -> resolved |
2020-10-11 19:32:59 | iritkatriel | set | nosy: + iritkatrielmessages: + |
2020-04-21 23:12:57 | furkanonder | set | messages: + |
2020-04-18 18:14:58 | miss-islington | set | messages: + |
2020-04-18 18:14:44 | miss-islington | set | messages: + |
2020-04-18 18:09:30 | miss-islington | set | pull_requests: + <pull%5Frequest18923> |
2020-04-18 18:09:24 | miss-islington | set | pull_requests: + <pull%5Frequest18922> |
2020-04-18 18:09:13 | miss-islington | set | nosy: + miss-islingtonmessages: + |
2020-04-01 00:21:22 | furkanonder | set | messages: + |
2020-04-01 00:17:13 | furkanonder | set | keywords: + patchnosy: + furkanonderpull_requests: + <pull%5Frequest18626>stage: needs patch -> patch review |
2017-02-18 20:47:59 | serhiy.storchaka | set | nosy: + alexandre.vassalotti, serhiy.storchakastage: needs patchtype: behaviorversions: + Python 3.7, - Python 3.4 |
2017-02-18 20:47:07 | serhiy.storchaka | link | issue29597 superseder |
2016-07-27 17:07:25 | july | create |