[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

Serhiy Storchaka storchaka at gmail.com
Fri Apr 26 23:36:13 CEST 2013


Thank you for your answers, Barry. Eli already answered me most of my 
questions.

20.04.13 22:18, Barry Warsaw написав(ла):
> On Apr 13, 2013, at 11:31 AM, Serhiy Storchaka wrote:
>>> The str and repr of the enumeration class also provides useful information::
>>>
>>>       >>> print(Colors)
>>>       <Colors {red: 1, green: 2, blue: 3}>
>>>       >>> print(repr(Colors))
>>>       <Colors {red: 1, green: 2, blue: 3}>
>>
>> Does the enumeration's repr() use str() or repr() for the enumeration values?
>
> No, enumeration values have different reprs and strs.

Yes, values can have different reprs and strs (but ints haven't). What 
of them uses repr of an enumeration item? I.e. what is str(Noises): 
'<Noises {dog: bark}>' or '<Noises {dog: "bark"}>'?

class Noises(Enum)
     dog = 'bark'

flufl.enum uses str(), but is it intentional? If yes, than it should be 
specified in the PEP.

>>> But if the value *is* important,  enumerations can have arbitrary values.
>>
>> Should enumeration values be hashable?
>>
>> At least they should be comparable ("Iteration is defined as the sorted order
>> of the item values").
>
> Given my previous responses, these questions should be already answered.

Eli and you have missed my first question. Should enumeration values be 
hashable? If yes (flufl.enum requires hashability), then this should be 
specified in the PEP. If no, then how you implements __getitem__? You 
can use binary search (but values can be noncomparable) or linear search 
which is not efficient.




More information about the Python-Dev mailing list