PEP 354: Enumerations in Python

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Feb 27 19:52:22 EST 2006


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> Hmm, I also see the PEP doesn't specify what's supposed to happen with
>
>   Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
>   Solar_system = enum('sun', 'mercury', 'venus', 'earth',)  # etc.
>   print Weekdays.sun == Solar_system.sun
>
> so that's another shortcoming with the PEP. 

The PEP text specifies::

    Values within an enumeration cannot be meaningfully compared
    except with values from the same enumeration.  The comparison
    operation functions return ``NotImplemented`` when a value from an
    enumeration is compared against any value not from the same
    enumeration or of a different type

The Python parser knows what to do when a comparison returns
NotImplemented.

-- 
 \           "It ain't so much the things we don't know that get us in |
  `\      trouble. It's the things we know that ain't so."  -- Artemus |
_o__)                                  Ward (1834-67), U.S. journalist |
Ben Finney



More information about the Python-list mailing list