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

gh-105497: [Enum] Fix flag mask inversion when unnamed flags exist #106468

Merged
merged 2 commits into from Jul 11, 2023

Conversation

ethanfurman
Copy link
Member

@ethanfurman ethanfurman commented Jul 5, 2023

For example:

class Flag(enum.Flag):
    A = 0x01
    B = 0x02
    MASK = 0xff

~Flag.MASK is Flag(0)

This restores 3.10 behavior:

~Flag.A = <Flag.B: 2>
(~Flag.A).value = 2
~Flag.A is Flag.B = True
~Flag.A == Flag.B = True

~Flag.Mask = <Flag.0: 0>
(~Flag.Mask).value = 0
~Flag.Mask is Flag(0) = True
~Flag.Mask == Flag(0) = True

For example:

    class Flag(enum.Flag):
        A = 0x01
        B = 0x02
        MASK = 0xff

    ~Flag.MASK is Flag(0)
@ethanfurman ethanfurman added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir 3.11 only security fixes 3.12 bugs and security fixes needs backport to 3.11 only security fixes 3.13 bugs and security fixes needs backport to 3.12 bug and security fixes labels Jul 5, 2023
@ethanfurman ethanfurman self-assigned this Jul 5, 2023
@ethanfurman ethanfurman requested review from ambv and hugovk July 5, 2023 21:45
@ethanfurman
Copy link
Member Author

That last commit should say IntFlag is KEEP -- Enum s don't have boundaries.

@ambv ambv merged commit 95b7426 into python:main Jul 11, 2023
21 checks passed
@miss-islington
Copy link
Contributor

Thanks @ethanfurman for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 11, 2023
…ist (pythonGH-106468)

For example:

    class Flag(enum.Flag):
        A = 0x01
        B = 0x02
        MASK = 0xff

    ~Flag.MASK is Flag(0)
(cherry picked from commit 95b7426)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@bedevere-bot
Copy link

GH-106620 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 11, 2023
…ist (pythonGH-106468)

For example:

    class Flag(enum.Flag):
        A = 0x01
        B = 0x02
        MASK = 0xff

    ~Flag.MASK is Flag(0)
(cherry picked from commit 95b7426)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Jul 11, 2023
@bedevere-bot
Copy link

GH-106621 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 11, 2023
Yhg1s pushed a commit that referenced this pull request Jul 11, 2023
…xist (GH-106468) (#106620)

gh-105497: [Enum] Fix flag mask inversion when unnamed flags exist (GH-106468)

For example:

    class Flag(enum.Flag):
        A = 0x01
        B = 0x02
        MASK = 0xff

    ~Flag.MASK is Flag(0)
(cherry picked from commit 95b7426)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Yhg1s pushed a commit that referenced this pull request Jul 11, 2023
…xist (GH-106468) (#106621)

gh-105497: [Enum] Fix flag mask inversion when unnamed flags exist (GH-106468)

For example:

    class Flag(enum.Flag):
        A = 0x01
        B = 0x02
        MASK = 0xff

    ~Flag.MASK is Flag(0)
(cherry picked from commit 95b7426)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@ethanfurman ethanfurman deleted the enum-invert branch February 1, 2024 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 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

Successfully merging this pull request may close these issues.

None yet

4 participants