Python Enum: A Duplicate Value Becomes a Silent Alias (tested)
Assigning the same value to two different Enum member names is valid Python -- no error, no warning. We measured what actually happens to the second name, and it's not a second member: it becomes an invisible alias of the first, and disappears from everywhere except an explicit name lookup.
1. The second member with a duplicate value vanishes from iteration
import enum
class Status(enum.Enum):
ACTIVE = 1
ENABLED = 1 # same value as ACTIVE
INACTIVE = 2
print(list(Status))
print(len(Status))
[<Status.ACTIVE: 1>, <Status.INACTIVE: 2>]
2
Measured: Status was defined with three names, but iterating it and calling len() both show only two members. ENABLED isn't gone -- it's an alias for ACTIVE, Enum's documented behavior for any member sharing an already-used value. It just never shows up unless you know to look for it.
2. ENABLED still "exists" -- it just always resolves to ACTIVE
import enum
class Status(enum.Enum):
ACTIVE = 1
ENABLED = 1
INACTIVE = 2
print(Status.ENABLED)
print(Status.ACTIVE is Status.ENABLED)
print(Status['ENABLED'])
print(Status(1))
Status.ACTIVE
True
Status.ACTIVE
Status.ACTIVE
Measured: Status.ENABLED works as an attribute access and even prints as Status.ACTIVE -- the name you typed is simply gone from the object's identity. Status['ENABLED'] (name-based lookup) still finds it via Status.__members__, which does list both names, but every other common way of inspecting the enum (iteration, len(), repr(), value lookup) shows only ACTIVE.
3. Prevent it with @enum.unique if duplicates should be an error
import enum
try:
@enum.unique
class Status(enum.Enum):
ACTIVE = 1
ENABLED = 1
INACTIVE = 2
except ValueError as e:
print(e)
duplicate values found in <enum 'Status'>: ENABLED -> ACTIVE
Measured: adding @enum.unique above the class turns this exact situation into an immediate ValueError at class-definition time, naming the duplicate. Without it, a copy-paste mistake that accidentally reuses a value (easy to do with sequential integers or status codes) compiles cleanly and silently drops a member from everything except name lookup -- worth adding by default on any Enum where every member is meant to be distinct.
Frequently asked questions
What happens if two Python Enum members have the same value?
The second one becomes a silent alias of the first -- we measured it disappearing from list(Enum), len(Enum), and repr(), even though Status.ENABLED still works as an attribute and resolves to Status.ACTIVE.
Does Python raise an error for duplicate Enum values?
Not by default -- we measured a class with two same-valued members defining cleanly with no warning. Adding the @enum.unique decorator does make it raise ValueError at class-definition time.
Why doesn't my Enum member show up when I iterate over the class?
It's likely an alias -- we measured this happening whenever a member's value duplicates an earlier member's value; only the first name with that value appears in iteration, len(), and repr().
How do I force all Enum values to be unique in Python?
Decorate the class with @enum.unique. We confirmed this raises ValueError immediately, naming which member is a duplicate of which, instead of silently creating an alias.
Can Status['ENABLED'] still find an aliased Enum member?
Yes -- we measured name-based lookup via Status['ENABLED'] and Status.__members__ still finding the alias name, even though it's invisible to list(Status), len(Status), and repr().
Written with AI assistance. Measured on 2026-10-04 with Python 3.13.5's built-in enum module: defined an Enum with two member names sharing the same integer value, then checked iteration (list(Enum)), len(), repr(), and name-based lookup (Enum['NAME']) for the second name. PlainHeaders is our extension; Python's enum module is built in.