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 serhiy.storchaka
Recipients alexandre.vassalotti, barry, ethan.furman, pitrou, python-dev, serhiy.storchaka
Date 2014-02-08.07:11:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <5801813.akqDBUrD3H@raxxla>
In-reply-to <1391817655.47.0.806563406985.issue20534@psf.upfronthosting.co.za>
Content
> -------------------------------------------------------------------------
> The object class implements both __reduce__() and __reduce_ex__();
> however, if a subclass overrides __reduce__() but not __reduce_ex__(),
> the __reduce_ex__() implementation detects this and calls __reduce__().
> -------------------------------------------------------------------------

This is about default  object.__reduce_ex__() implementation. But base class 
can override it.

>>> import enum, pickle
>>> class C(int):
...     def __reduce_ex__(self, proto):
...         return C, (int(self),)
... 
>>> class E(C):
...     X = C(42)
... 
>>> y = C(42)
>>> pickle.loads(pickle.dumps(y))
42
>>> type(pickle.loads(pickle.dumps(y)))
<class '__main__.C'>
>>> pickle.loads(pickle.dumps(E.X))
42
>>> type(pickle.loads(pickle.dumps(E.X)))
<class '__main__.C'>

Well, the direct cause is that the Enum class in question failed to define 
__getnewargs__; the indirect cause is that without __getnewargs__ the 
metaclass will call _make_class_unpicklable.

> Well, the direct cause is that the Enum class in question failed to define
> __getnewargs__; the indirect cause is that without __getnewargs__ the
> metaclass will call _make_class_unpicklable.
> 
> So neither the enum nor its members should pickle.

Actually they don't pickle due to wrong __module__. After adding

    NEI.__module__ = NamedInt.__module__ = __name__

PicklingError no longer raised for enum class.

And "BadPickle.__qualname__ = 'BadPickle'" in test_exploding_pickle is 
redundant, because BadPickle.__qualname__ already is 'BadPickle' (due to the 
module argument in constructor).
History
Date User Action Args
2014-02-08 07:11:43serhiy.storchakasetrecipients: + serhiy.storchaka, barry, pitrou, alexandre.vassalotti, ethan.furman, python-dev
2014-02-08 07:11:43serhiy.storchakalinkissue20534 messages
2014-02-08 07:11:43serhiy.storchakacreate