[Python-ideas] Enum and serialization
Nick Coghlan
ncoghlan at gmail.com
Sat Jul 20 08:38:00 CEST 2013
On 20 July 2013 02:07, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 07/18/2013 10:11 PM, Nick Coghlan wrote:
>>
>> On 19 July 2013 04:24, Ethan Furman <ethan at stoneleaf.us> wrote:
>>>
>>>
>>> For the 3.4 stdlib there are two proposals on the table:
>>>
>>> 1) for IntEnum and FloatEnum cast the member to int or float, then
>>> procede;
>>>
>>> 2) for any Enum, extract the value and proceed.
>>
>>
>> 3) Only change repr (not str) in IntEnum
>>
>> I know Guido doesn't like it, but I still think the backwards
>> compatibility risk is too high to use them to replace constants in the
>> standard library if they change the output of __str__. Debugging only
>> needs repr, and we can make sure stdlib error messages use repr, too.
>
>
> The issue with that solution is json uses repr, not str, for floats. So we
> would still have a problem.
Gah, I forgot about that (and I think it came up on the issue tracker, too).
Perhaps we should include a "Converting existing constants to Enums"
section in the enum docs, noting some of the backwards compatibility
implications for serialisation when using IntEnum or similar subtypes?
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list