EnumMetaclass should have a __instancecheck__ method
Bug #1172866 reported by
Barry Warsaw
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
flufl.enum |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
There's been some discussion on python-dev that enum items pass an instance check against their enum class. E.g.
>>> X = Enum('X', 'a b c')
>>> Y = Enum('Y', 'z y x')
>>> class Z(Y):
... d = 4
... e = 5
...
>>> isinstance(Z.d, Y)
True
>>> isinstance(Z.d, Z)
True
>>> isinstance(Z.d, X)
False
>>> isinstance(Y.z, Y)
True
>>> isinstance(Y.z, Z)
False
To do this, we could add the following method to EnumMetaclass:
def __instancecheck
return instance.enum is cls or cls in instance.
I haven't decided whether it's a good idea or not though, since the semantics seem weird to me.
Changed in flufl.enum: | |
status: | New → Won't Fix |
To post a comment you must log in.