[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-13 Thread Barry A. Warsaw
Changes by Barry A. Warsaw : -- nosy: +barry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-12 Thread Nick Coghlan
Nick Coghlan added the comment: Ah, you're right, I forgot that was the other reason for disallowing extensions through subclassing. To get extensions to work right, you need to flip it around so that isinstance(Color.red, MoreColor) is True, while isinstance(MoreColor.magenta, Color) is Fals

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-12 Thread Ethan Furman
Ethan Furman added the comment: Not trying to push, but if I don't write it down now, I'll forget later. ;) What does adding new members gain us? If I have a func xyz() that's expecting a Color, a MoreColor will work sometimes and blow up other times. Or are you saying that we may have a func

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-12 Thread Nick Coghlan
Nick Coghlan added the comment: Simply removing the restriction isn't actually appropriate, as the variants that allow addition of new members should *not* allow addition of new descriptors. That's why I'm wondering if the current subclassing restriction is wrong: if you subclass an Enum deri

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-12 Thread Ethan Furman
Ethan Furman added the comment: Make it simpler: class EnumMeta(): allow_subclass = False class MyEnumMeta(EnumMeta): allow_subclass = True -- ___ Python tracker ___ _

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-12 Thread Nick Coghlan
Nick Coghlan added the comment: I elaborated on this point in http://python-notes.boredomandlaziness.org/en/latest/python3/enum_creation.html#support-for-alternate-declaration-syntaxes However, I'm now wondering if the problem is simply that the "no extension of enums" rule is more restrictive

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-11 Thread Nick Coghlan
Nick Coghlan added the comment: I don't think that would be wise - there's currently other logic in _get_mixins that subclasses would then have to duplicate. I was thinking more of an allow_subclass() API that subtypes could override to always return True. EnumMeta would then just factor the r

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-11 Thread Ethan Furman
Ethan Furman added the comment: I'm sure this is a dumb question, but I have lots of them so thought I'd share. Can this issue be resolved simply by making the `_get_mixins` method `get_mixins`? -- nosy: +ethan.furman ___ Python tracker

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-11 Thread Nick Coghlan
Changes by Nick Coghlan : -- dependencies: +Code, test, and doc review for PEP-0435 Enum ___ Python tracker ___ ___ Python-bugs-list m

[issue17954] Support creation of extensible enums through metaclass subclassing

2013-05-11 Thread Nick Coghlan
New submission from Nick Coghlan: 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