enum: auto() Gives Sequential Ints in Enum, Powers of 2 in Flag (tested)
enum.auto() looks like a base-class-independent way to say "just pick the next value" -- the same call, used the same way, regardless of which enum flavor you inherit from. We measured whether it actually produces the same sequence in a plain Enum versus a Flag, the kind of thing you'd hit switching a status-code enum to a bitwise-combinable one.
1. Plain Enum: auto() counts up 1, 2, 3, ...
import enum
class Color(enum.Enum):
RED = enum.auto()
GREEN = enum.auto()
BLUE = enum.auto()
print([c.value for c in Color])
[1, 2, 3]
Measured: in a plain Enum, auto() assigns sequential integers starting at 1 -- exactly the behavior most people expect from "just number them."
2. Flag: the identical code gives powers of two instead
import enum
class ColorFlag(enum.Flag):
RED = enum.auto()
GREEN = enum.auto()
BLUE = enum.auto()
print([c.value for c in ColorFlag])
[1, 2, 4]
Measured: the exact same three lines of member definitions, only changing the base class from Enum to Flag, produce 1, 2, 4 instead of 1, 2, 3. auto() is base-class-aware: Flag (and IntFlag) override its value-picking logic to hand out the next unused power of two, so members can be combined with | without colliding bits. If any of these values were ever stored, serialized, or compared against a hardcoded int (a database column, a JSON field, an API contract), converting the class from Enum to Flag for bitwise-combination support silently changes what every member's underlying value is.
3. A non-power-of-two explicit value still lets auto() continue correctly -- but becomes invisible
import enum
class Weird(enum.Flag):
A = 3 # explicit, not a single bit (binary 11)
B = enum.auto()
print([m.value for m in Weird])
print(list(Weird))
print(Weird.A, Weird.A.value)
[4]
[<Weird.B: 4>]
Weird.A 3
Measured: auto() for B correctly continues from the next free bit (4, since 3 already uses bits 1 and 2), but A itself -- having a composite, multi-bit value instead of a single flag bit -- is treated as a pseudo-member and vanishes from list(Weird), the same way a duplicate-value alias does. Weird.A still resolves by name and still reports its correct value; it just doesn't appear when iterating the class. If you need every value to show up consistently in list()/iteration, keep every explicit Flag value a single power of two and let auto() handle the rest.
Frequently asked questions
Does enum.auto() produce the same values in Enum and Flag?
No -- we measured enum.auto() giving sequential integers (1, 2, 3) in a plain Enum, but powers of two (1, 2, 4) for the identical member definitions in a Flag, because Flag overrides auto()'s value-generation to keep each member a distinct bit.
What happens if I change an Enum's base class to Flag but keep using auto()?
Every member's underlying value silently changes from sequential integers to powers of two -- we confirmed this with identical code differing only in base class. Anything that stored, serialized, or compared the old integer values will see different numbers after the switch.
Can a Flag member have a value that's not a power of two?
Yes, if assigned explicitly (e.g. A = 3) -- we measured auto() for a later member still correctly picking the next unused single bit, but the non-power-of-two member itself disappears from list(Flag) iteration, similar to how a duplicate-value alias disappears.
Does a Flag member with a composite value still work even though it's missing from list()?
Yes -- we measured Weird.A and Weird['A'] still resolving correctly by name with its correct value (3), even though it was absent from list(Weird) and from the set of values auto() considers already used.
How do I make sure every Flag member shows up when iterating the class?
Only use single power-of-two values (1, 2, 4, 8, ...) for explicit Flag members, or use enum.auto() for all of them -- we confirmed auto() always picks the next free single bit, keeping every member visible in iteration.
Written with AI assistance. Measured on 2026-10-04 with Python 3.13.5's built-in enum module: defined the same three member names using enum.auto() in a plain Enum, then in a Flag, and compared the resulting values, plus checked what happens when a Flag member has an explicit non-power-of-2 value followed by auto(). PlainHeaders is our extension; Python's enum module is built in.