Skip to content

Feature request: implicit-flag-overlap #8102

Closed
@jayaddison

Description

@jayaddison

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions