New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enum.Enum is False-y #70935
Comments
>>> import enum
>>> bool(enum.Enum)
False
>>> bool(enum.IntEnum)
False This behaviour is relatively unexpected for classes, and can lead to subtle bugs such as the following: https://bitbucket.org/ambv/singledispatch/issues/8/inconsistent-hierarchy-with-enum |
I guess it's marked 2.7 because of the enum34 backport? There's no enum in the 2.7 stdlib. I believe this was brought up before on one of the lists but I don't recall the outcome of the discussion, except that for IntEnum the behavior is correct. I tend to agree that for plain Enum it's a problem, the question is whether we can fix it without breaking code that accidentally relies on this behavior. |
Oh wait. The *class* is False-y? That's definitely a bug, just fix it. |
Yes, I didn't find a separate bug tracker for the enum34 backport, which is why I included that version here.
Do you remember the argument? I agree that IntEnum *instances* may be falsy, but IntEnum classes I don't see why. That said, if an IntEnum *class* has to be false-y, then there's no real point in fixing just Enum (you can pass an IntEnum instance to singledispatch() too). |
Ok, we posted at the same time :-) Yes, the class is false-y. |
Just reading the code now, the reason is that EnumMeta pretends to be a collection (it defines a __len__ and an __iter__). |
EnumMeta /is/ a collection (at least in the same sense the dict class is a collection). ;) Fix is on it's way... |
See also bpo-23008. |
New changeset 772805538caf by Ethan Furman in branch '3.4': New changeset f840608f79da by Ethan Furman in branch '3.5': New changeset 2fc61f8ee2d2 by Ethan Furman in branch 'default': |
Enum classes are now Truth-y in 3.4, 3.5, enum34, and aenum. :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: