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

Ethan Furman ethan at stoneleaf.us
Fri Apr 26 18:25:56 CEST 2013


On 04/26/2013 08:50 AM, Larry Hastings wrote:
> FWIW I'm +0.5 on "the enum metaclass ignores callables and
> descriptors".  This seems reasonably Pythonic, much more so than "ignore
> everything except ints and strings".  And as long as we're
> special-casing it I think we should opt for flexibility. Certainly I see
> nothing wrong with enums of float, complex, Decimal, and Fraction, so I
> don't see a good place to draw the line with a whitelist.

A whitelist, if we go that route, should be on a per Enum basis -- so 
something like:

   class Planets(str, Enum):
       PLUTO = 'it is too a planet!'
       MERCURY = 'definitely a planet'
       SATURN = 'darn big planet'

       solar_mass = 82738273  # or some  really big number
       light_year = 1827499   # another really big number (of feet!)

       def horrorscope(self, message):
           return ('%s will be in retrograde... '
              'don't communicate today.' % self)


and only PLUTO, MERCURY, and SATURN would be converted to enums.

--
~Ethan~


More information about the Python-Dev mailing list