This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Enum does not recognize enum.auto as unique values
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: ethan.furman, josh.r, max
Priority: normal Keywords:

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:47adminsetgithub: 74702
2017-05-31 10:02:53maxsetstatus: open -> closed
resolution: not a bug
messages: + msg294831

stage: resolved
2017-05-31 05:56:40josh.rsetnosy: + josh.r
messages: + msg294813
2017-05-31 04:16:33rhettingersetassignee: ethan.furman

nosy: + ethan.furman
2017-05-31 02:08:08maxcreate