-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Pattern matching on Enum.name fails to distinguish between members with duplicate values #127375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did some stuff.
This is because when you give members the same value, they actually get replaced by the same object. The extra name is just an alias - |
Thanks that is super helpful! Is this a deliberate feature of enums or is it a limitation? |
It's deliberate behaviour yes. You can call an enum class with a value to lookup the corresponding member - |
Ah I see of course - a nice feature indeed. Thank you again. |
Bug report
Bug description:
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
The text was updated successfully, but these errors were encountered: