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

Rurpy rurpy at yahoo.com
Sun Apr 21 06:55:25 CEST 2013

On 04/20/2013 01:42 PM, Barry Warsaw wrote:> On Apr 13, 2013, at 12:51 PM, Steven D'Aprano wrote:
>>What's the justification for this [unique values] restriction? I have
>>looked in the PEP, and didn't see one.
> If you allowed this, there would be no way to look up an enumeration item by
> value.  This is necessary for e.g. storing the value in a database.  If you
> know that the "insect" column is an INTEGER that represents an enumeration
> item of Insect, then you can just store the int value in the column.  To
> reconstitute the actual enumeration item when you read the column back from
> the database, you need to be able to look up the item by value.

Composite keys have been part of relational databases from
their inception.  If you want to store an enumeration value
in a database when non-unique values are possible, you can 
do so simply by storing the name, value pair; i.e. use two 
columns instead of one.  Of course this does not preclude 
storing just the value when you know they will be unique.
But it is not true that unique values are *required* for 
storing enumeration values in a database.

More information about the Python-Dev mailing list