Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
Assignees
ethanfurman
Labels
3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@alien-valkyrie

Description

@alien-valkyrie

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 (specificallyGH-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:

fromenumimportEnumclassDirections(Enum):DOWN_ONLY=frozenset({"sc"})UP_ONLY=frozenset({"cs"})UNRESTRICTED=frozenset({"sc","cs"})dirs= {"sc"}# in 3.13, this raises ValueErrorthe_dirs=Directions(dirs)assertthe_dirsisDirections.DOWN_ONLY

Note that in this example (which is based onour use case) there's the obvious user-side fix ofDirections(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

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp