Is there a particular reason why, in Python, the objects that
represent enums don't inherit from a parent EnumObject type?

It would be useful if they, and the other objects, inherited from base
objects - specifically, `isinstance` could be used for testing:
>>> isinstance(MyEnum, EnumObject)
True
>>> isinstance(MyStruct, StructObject)
True

etc.

This would allow for monkey-patching the "base" object with some handy
class methods and having them be inherited by the child classes.
Here's a trivial example:

>>> def key_from_val(cls, val):
...   for n, v in cls.__dict__.items():
...     if n.isupper() and v is val:
...       return n
...
>>> EnumObject.key_from_val = classmethod(key_from_val)
>>> MyEnumObject.key_from_val(1)
'FIRST_ENUM_ITEM'

-- 
Phillip B Oldham
[email protected]
+44 (0) 7525 01 09 01

Reply via email to