Author ncoghlan
Recipients ncoghlan
Date 2013-05-11.13:55:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Guido chose to follow Java in enforcing the invariant "Enum members are instances of that Enum" for PEP 435 (i.e. "assert (all(isinstance(x, SomeEnum) for x in SomeEnum)"). As a consequence, the Enum metaclass prevents subclassing of Enums with defined members.

This is a reasonable design choice, but one that limits the applicability of the standard library enum solution for use cases that currently rely on this feature of a custom enum implementation (including flufl.enum, the original inspiration for this feature).

An alternative reasonable design choice is to allow extension of enumerations (similar to flufl.enum) and relax the invariant to "Enum members are an instance of that Enum or an Enum-derived parent class of that Enum" (i.e. "assert (all(issubclass(type(x), Enum) and type(x) in SomeEnum.mro() for x in SomeEnum)")

There is no need to support this directly in the standard library, but it would be valuable to make it straightforward to support in an Enum variant by subclassing the standard metaclass (similar to the customisation mechanisms provided to support things like autonumbered enums through a derived metaclass). Currently, implementing this behaviour involves overriding a private method of the metaclass (EnumMetaclass._get_mixins)
Date User Action Args
2013-05-11 13:55:34ncoghlansetrecipients: + ncoghlan
2013-05-11 13:55:34ncoghlansetmessageid: <>
2013-05-11 13:55:34ncoghlanlinkissue17954 messages
2013-05-11 13:55:34ncoghlancreate