[Python-ideas] PEP for enum library type?
Georg Brandl
g.brandl at gmx.net
Wed Feb 13 00:57:38 CET 2013
Am 12.02.2013 20:45, schrieb Barry Warsaw:
> On Feb 12, 2013, at 09:07 AM, Ethan Furman wrote:
>
>>The result of the implementation I've been playing with looks something like:
>>
>>class Color(Enum):
>> type = 'sequence'
>> RED, GREEN, BLUE
>>
>>class Geometry(Enum):
>> type = 'unique'
>> LEFT, RIGHT, TOP, BOTTOM
>> WEST, EAST, NORTH, SOUTH
>>
>>class FieldType(Enum):
>> type = 'flag'
>> BINARY, AUTOINC, NULLABLE
I am also against this. It requires special support and heuristics in static
analysis tools in order not to flag these as errors. It will be annoying.
> IMHO, none of these approach the simplicity and explicitness of this API:
>
> class Color(Enum):
> RED = 1
> GREEN = 2
> BLUE = 3
We could even allow
class Color(Enum):
RED = 1
GREEN = ... # becomes 2
BLUE = ... # 3
MAGENTA = 5
FLUFL = ... # 6
class Color(FlagEnum):
RED = 1
GREEN = ... # becomes 2
BLUE = ... # 4
MAGENTA = 16
FLUFL = ...
class Color(StringEnum):
RED = ... # becomes 'red'
GREEN = ... # etc.
BLUE = ...
Georg
More information about the Python-ideas
mailing list