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.CONFORM behavior breaks backwards compatibility #103365

Closed
Assignees
ethanfurman
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@benburrill

Description

@benburrill

Encountered yet another breaking change for enums. There are two problems here:

  • CONFORM doesn't "conform" to members that are partially unsupported
  • CONFORM does not match the previous behavior for Flag. It used to be more similar to STRICT, but STRICT also doesn't allow partially unsupported members, while Flag in 3.10 did.

Example to reproduce:

importenumclassSkipFlag(enum.Flag):A=1B=2C=4|Bprint(SkipFlag.Cin (SkipFlag.A|SkipFlag.C))classSkipIntFlag(enum.IntFlag):A=1B=2C=4|Bprint(SkipIntFlag.Cin (SkipIntFlag.A|SkipIntFlag.C))print(SkipIntFlag(42).value)print(SkipFlag(42).value)

In Python 3.10.6, this code outputs:

TrueTrue42Traceback (most recent call last):...ValueError: 42 is not a valid SkipFlag

In Python 3.11.2:

FalseTrue422

Having such members as C is useful to create a flags that are distinct from B but always implies B.

In a previous comment bug report it was stated that the previous behavior of Flag was CONFORM:

Actually, won't need a deprecation period, since the proper default forFlag isCONFORM as that matches previous behavior.

Originally posted by@ethanfurman in#96865 (comment)

Clearly this is incorrect. The previous behavior was more similar to STRICT, but there appears to be no precise equivalent in Python 3.11 to the old behavior. Using STRICT in Python 3.11,SkipFlag.A | SkipFlag.C would fail to be created completely.

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibStandard 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