[Python-Dev] enum discussion: can someone please summarize open issues?
Ethan Furman
ethan at stoneleaf.us
Mon Apr 29 08:50:16 CEST 2013
On 04/28/2013 09:54 PM, Guido van Rossum wrote:
> On Sunday, April 28, 2013, Ethan Furman wrote:
>
>> Enums are the same: they could return brand new instances every time, and programs using `==` to compare will keep
>> on working. That they don't is an implementation detail.
>
> Whoa. In this case the identity property is not just an implementation issue, it is part of the spec. Same for bool.
> (But == works too.)
I realize that, and I have no problems with the singleton (multiton?) approach; however, part of the spec is that a
subclass shares the enum items, and if the enum items are actual instances of the type that will no longer be correct.
In other words, currently:
class Color(Enum):
red = 1
green = 2
blue = 3
class MoreColor(Color):
cyan = 4
magenta = 5
yellow = 6
black = 7
MoreColor.red is Color.red # True
But as soon as:
type(Color.red) is Color # True
type(MoreColor.red) is MoreColor # True
then:
Color.red is MoreColor.red # must be False, no?
If that last statement can still be True, I'd love it if someone showed me how.
--
~Ethan~
P.S. Apologies for the additional post.
More information about the Python-Dev
mailing list