Skip to content
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

Enum by-value lookup no longer compares hashable argument to unhashable values #125710

Closed
alien-valkyrie opened this issue Oct 18, 2024 · 0 comments
Assignees
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes needs backport to 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@alien-valkyrie
Copy link

alien-valkyrie commented Oct 18, 2024

Bug report

Bug description:

When defining enum members with hashable values (e.g. frozensets), it was previously (prior to 3.13) possible to look those members up by passing in unhashable values (e.g. sets) that compare equal to those original values.
This no longer works as of 3.13 (specifically GH-112514), since the unhashable argument is now only compared to unhashable enum values. I haven't been able to find any documentation of this change in the What's New or even the changelog, so I'm assuming it's not entirely intended.

Reproducible example:

from enum import Enum

class Directions(Enum):
    DOWN_ONLY = frozenset({"sc"})
    UP_ONLY = frozenset({"cs"})
    UNRESTRICTED = frozenset({"sc", "cs"})

dirs = {"sc"}
# in 3.13, this raises ValueError
the_dirs = Directions(dirs)
assert the_dirs is Directions.DOWN_ONLY

Note that in this example (which is based on our use case) there's the obvious user-side fix of Directions(frozenset(dirs)), but if there happens to be another hashable-equal-to-unhashable use case outside of (frozen)sets, such a workaround might not exist.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

@alien-valkyrie alien-valkyrie added the type-bug An unexpected behavior, bug, or error label Oct 18, 2024
alien-valkyrie added a commit to alien-valkyrie/freeciv that referenced this issue Oct 18, 2024
This is a workaround for python/cpython#125710

See RM #975

Signed-off-by: Alina Lenk <[email protected]>
@ethanfurman ethanfurman self-assigned this Oct 18, 2024
@ethanfurman ethanfurman added stdlib Python modules in the Lib dir 3.13 bugs and security fixes 3.14 new features, bugs and security fixes needs backport to 3.13 bugs and security fixes labels Oct 19, 2024
alien-valkyrie added a commit to freeciv/freeciv that referenced this issue Oct 20, 2024
This is a workaround for python/cpython#125710

Reported by Marko Lindqvist

See RM #975

Signed-off-by: Alina Lenk <[email protected]>
alien-valkyrie added a commit to freeciv/freeciv that referenced this issue Oct 20, 2024
This is a workaround for python/cpython#125710

Reported by Marko Lindqvist

See RM #975

Signed-off-by: Alina Lenk <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 22, 2024
…mber values (pythonGH-125735)

(cherry picked from commit aaed91c)

Co-authored-by: Ethan Furman <[email protected]>
ethanfurman added a commit that referenced this issue Oct 22, 2024
…ember values (GH-125735) (GH-125851)

gh-125710: [Enum] fix hashable<->nonhashable comparisons for member values (GH-125735)
(cherry picked from commit aaed91c)

Co-authored-by: Ethan Furman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes needs backport to 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants