[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)
Philip Jenvey pjenvey at underboss.org
Sun Apr 28 01:07:45 CEST 2013
- Previous message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Next message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Apr 27, 2013, at 2:57 PM, Guido van Rossum wrote:
On Sat, Apr 27, 2013 at 1:01 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
It seems to me that the most common case will be a simple name mapping, in which case one can do:
Planet = Enum.make('Planet', 'MERCURY VENUS EARTH') and be done with it. That looks horrible.
Call me crazy, but might I suggest:
class Planet(Enum, values='MERCURY VENUS EARTH'): """Planets of the Solar System"""
I've always wanted something similar for namedtuples, such as:
class Point(NamedTuple, field_names='x y z'): """Planet location with Sun as etc"""
Especially when the common idiom for specifying namedtuples w/ docstrings looks similar but leaves a lot to be desired w/ the required duplication of the name:
class Point(namedtuple('Point', 'x y z')): """Planet location with Sun as etc"""
(Raymond's even endorsed the former):
http://bugs.python.org/msg111722
-- Philip Jenvey
- Previous message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Next message: [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]