Enumeration idioms: Values from different enumerations

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Dec 17 01:37:34 CET 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> All in all, comparing by object identity doesn't sound too good.
> Maybe you want to have the enum contain its own name internally, and
> do a string comparison.

The "__eq__ compares identity" was a glib pseudo-implementation; I
didn't think it through. The existing 'enum' implementation doesn't
use identity, and future ones won't either.

The intended meaning was more like:

    class EnumValue(object):
        # ...
        def __eq__(self, other):
            result = compare_attribute_values(self, other)
            return result

In other words, identity doesn't matter, but every value from every
enumeration will compare inequal to each other. If an EnumValue
instance is copied, the copies will compare equal.

-- 
 \     "Remember men, we're fighting for this woman's honour; which is |
  `\                probably more than she ever did."  -- Groucho Marx |
_o__)                                                                  |
Ben Finney <http://www.benfinney.id.au/>



More information about the Python-list mailing list