-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Closed
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
# How to reproduce
from enum import Enum
class Registers(Enum):
SP = 31 # Stack pointer
XZR = 31 # Zero register
# Example
for token in ["XZR"]:
match token:
case Registers.XZR._name_:
print("Matched XZR")
case Registers.SP._name_:
print("Matched SP")
case _:
print("No match")
# Current behavior: Always matches SP case first because SP is defined first
# Expected behavior: Should match XZR case when checking against XZR._name_
The issue appears to be that when pattern matching against _name_
of enum members with duplicate values, Python always matches the first enum member with that value, regardless of which _name_
is being matched against. This makes it impossible to differentiate between enum members with the same value in pattern matching contexts.
This behavior is particularly problematic in cases like ARM assembly parsing where different registers (SP and XZR) share the same value (31) but have distinct semantic meanings and need to be handled differently.
much obliged,
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error