homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients corona10, eric.snow, erlendaasland, pablogsal, phsilva, shihai1991, skrah, vstinner
Date 2020年06月18日.14:06:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592489196.72.0.133874484646.issue40077@roundup.psfhosted.org>
In-reply-to
Content
PR 20960 (_bz2 module) triggers an interesting question. The effect of converting a static type to a heap type on pickle, especially for protocols 0 and 1.
pickle.dumps(o, 0) calls object.__reduce__(o) which calls copyreg._reduce_ex(o, 0).
copyreg._reduce_ex() behaves differently on heap types:
 ...
 for base in cls.__mro__:
 if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
 break
 else:
 base = object # not really reachable
 ...
There are 3 things which impacts serialization/deserialization:
- Py_TPFLAGS_HEAPTYPE flag in the type flags
- Is __new__() overriden in the type?
- Py_TPFLAGS_BASETYPE flag in the type flags
Examples:
* In Python 3.7, _random.Random() cannot be serialized because it's a static type (it doesn't have (Py_TPFLAGS_HEAPTYPE)
* In master, _random.Random() cannot be deserialized because _random.Random() has __new__() method (it's not object.__new__())
History
Date User Action Args
2020年06月18日 14:06:36vstinnersetrecipients: + vstinner, phsilva, skrah, eric.snow, corona10, pablogsal, shihai1991, erlendaasland
2020年06月18日 14:06:36vstinnersetmessageid: <1592489196.72.0.133874484646.issue40077@roundup.psfhosted.org>
2020年06月18日 14:06:36vstinnerlinkissue40077 messages
2020年06月18日 14:06:36vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /