[Python-Dev] PEP 435: pickling enums created with the functional API
Eli Bendersky
eliben at gmail.com
Wed May 8 03:55:24 CEST 2013
On Tue, May 7, 2013 at 6:00 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On 07/05/13 23:34, Eli Bendersky wrote:
>
>> One of the contended issues with PEP 435 on which Guido pronounced was the
>> functional API, that allows created enumerations dynamically in a manner
>> similar to namedtuple:
>>
>> Color = Enum('Color', 'red blue green')
>>
>> The biggest complaint reported against this API is interaction with
>> pickle.
>> As promised, I want to discuss here how we're going to address this
>> concern.
>>
>
>
> Does this issue really need to be solved before 435 is accepted? As the
> Zen says:
>
> Now is better than never.
> Although never is often better than *right* now.
>
> Solving the pickle issue is a hard problem, but not a critical issue.
> namedtuple has had the same issue since its inception, only worse because
> there is no class syntax for namedtuple. This has not been a barrier to the
> success of namedtuple.
>
>
Agreed
> Or rather, the issue is not with Enum, or namedtuple, but pickle. Any
> dynamically-created type will have this issue:
>
> import pickle
>>>> def example(name):
>>>>
>>> ... return type(name, (object,), {})
> ...
>
>> instance = example("Foo")()
>>>> pickle.dumps(instance)
>>>>
>>> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> _pickle.PicklingError: Can't pickle <class '__main__.Foo'>: attribute
> lookup __main__.Foo failed
>
>
> I don't think it is unreasonable to chalk it up to a limitation of pickle,
> and say that unless you can meet certain conditions, you won't be able to
> pickle your instance.
>
> Either way, approval of PEP 435 should not be dependent on fixing the
> pickle issue.
>
Just to be clear- it was not my intention to delay PEP 435 because of this
issue. I don't see it as a blocker to pronouncement and from a private
correspondence with Guido, he doesn't either.
I merely wanted to start a separate thread because I didn't want this
discussion to overwhelm the pronouncement thread.
Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130507/b4223e39/attachment.html>
More information about the Python-Dev
mailing list