Skip to content

Composite Flag entries aren't listed as Enum members #43

Description

@mwhavens

When using the Flag enum class, entries that are composite with other entries omits them from the list of all enum entries, even if all entries are unique.

from aenum import Flag, auto
class SBInterfaceType(Flag):
    ALL = 0
    UNKNOWN = auto()
    URL = auto()
    PROD = auto()
    DEV = auto()
    S3 = auto()
    T3 = auto() | PROD | S3

[i for i in SBInterfaceTypes]

Result:
[<SBInterfaceTypes.UNKNOWN: 1>, <SBInterfaceTypes.URL: 2>, <SBInterfaceTypes.PROD: 4>, <SBInterfaceTypes.DEV: 8>, <SBInterfaceTypes.S3: 16>]
T3 is missing

T3 does appear in SBInterfaceType's _member_map_ but not in its _member_names_. Because it's not in the member_names, the Flag class's __iter__ method will skip it (it loops through all member_names to use as a key look up for member_map).

A fix that worked for me was to remove the is_single_bit check in the elif check in the following line of code:

and is_single_bit(value)

Though I'm not sure what the ramifications outside my use-case are for this change, or why that check was done in the first place.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions