Skip to content

gh-107538: [Enum] fix handling of inverted/negative values #132273

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ethanfurman
Copy link
Member

@ethanfurman ethanfurman commented Apr 8, 2025

correct Flag inversion to only flip flag bits; IntFlag still flips all bits -- this
only makes a difference in flag sets with missing values.

correct negative assigned values in flags; negative values are no longer
used as-is, but become inverted; i.e.

    class Y(self.enum_type):
        A = auto()
        B = auto()
        C = ~A        # aka ~1 aka 0b1 110 (from enum.bin()) aka 6
        D = auto()

    assert Y.C. is Y.B|Y.D

For example:

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

    ~Flag.MASK is Flag(0)
IntFlag will flip all bits -- this only makes a difference in flag sets with
missing values.
negative values are no longer used as-is, but become inverted; i.e.

    class Y(self.enum_type):
        A = auto()
        B = auto()
        C = ~A        # aka ~1 aka 0b1 110 (from enum.bin()) aka 6
        D = auto()

    assert Y.C. is Y.B|Y.D
@bedevere-app bedevere-app bot mentioned this pull request Apr 8, 2025
2 tasks
@ethanfurman ethanfurman self-assigned this Apr 8, 2025
@@ -0,0 +1 @@
Fix flag mask inversion when unnamed flags exist.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate NEWS entries?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing a different aspect of the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants