Issue 30517: Enum does not recognize enum.auto as unique values (original) (raw)

Issue30517

Created on 2017-05-31 02:08 by max, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg294804 - (view) Author: Max (max) * Date: 2017-05-31 02:08
This probably shouldn't happen: import enum class E(enum.Enum): A = enum.auto B = enum.auto x = E.B.value print(x) # <class 'enum.auto'> print(E(x)) # E.A The first print() is kinda ok, I don't really care about which value was used by the implementation. But the second print() seems surprising. By the same token, this probably shouldn't raise an exception (it does now): import enum @enum.unique class E(enum.Enum): A = enum.auto B = enum.auto C = object() and `dir(E)` shouldn't skip `B` in its output (it does now).
msg294813 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2017-05-31 05:56
You didn't instantiate auto; read the docs ( https://docs.python.org/3/library/enum.html#using-automatic-values ): auto is a class, you instantiate it to make instances for use. If you omit the parens, it's just a plain class, not a special value for automatic value assignment. You want: class E(enum.Enum): A = enum.auto() B = enum.auto()
msg294831 - (view) Author: Max (max) * Date: 2017-05-31 10:02
Ah sorry about that ... Yes, everything works fine when used properly.
History
Date User Action Args
2022-04-11 14:58:47 admin set github: 74702
2017-05-31 10:02:53 max set status: open -> closedresolution: not a bugmessages: + stage: resolved
2017-05-31 05:56:40 josh.r set nosy: + josh.rmessages: +
2017-05-31 04:16:33 rhettinger set assignee: ethan.furmannosy: + ethan.furman
2017-05-31 02:08:08 max create