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

Feature request: implicit-flag-overlap #8102

Closed
jayaddison opened this issue Jan 23, 2023 · 0 comments · Fixed by #8345
Closed

Feature request: implicit-flag-overlap #8102

jayaddison opened this issue Jan 23, 2023 · 0 comments · Fixed by #8345
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@jayaddison
Copy link
Contributor

Current problem

The following behaviour seemed confusing:

>>> from enum import IntFlag
>>> class TestFlag(IntFlag):
...     A = 1
...     B = 2
...     C = 3
... 
>>> print([i for i in TestFlag])
[<TestFlag.A: 1>, <TestFlag.B: 2>]

(note that this is an IntFlag, not an IntEnum)

Desired solution

The reason this happens is that Flag types are designed for setwise operations (bitwise operations, in the case of IntFlag), and, because C can be composed of A and B...

>>> int(TestFlag.A | TestFlag.B)
3
>>> int(TestFlag.C)
3

...internally, IntFlag considers C to be an alias -- and doesn't include it when iterating over the members of the flag.

A pylint message something along the lines of implicit-flag-overlap could be emitted by a relevant checker when scanning the class declaration.

Additional context

No response

@jayaddison jayaddison added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 23, 2023
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 23, 2023
@jayaddison jayaddison changed the title Question / idea: implicit-flag-overlap Feature request: implicit-flag-overlap Jan 24, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.0 milestone Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants