Skip to content

Flag auto() produces wrong value with multiple OR '|' operations. #42

Description

@mwhavens

auto() only factors in the last | operation on the right side. I've found a work around is to move the |'s to the left of auto but a fix should probably be done to resolve the code bug as well.

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

list(SBInterfaceTypes._member_map_.values())
print(SBInterfaceTypes.T3)

result: [<SBInterfaceTypes.ALL: 0>, <SBInterfaceTypes.UNKNOWN: 1>, <SBInterfaceTypes.URL: 2>, <SBInterfaceTypes.PROD: 4>, <SBInterfaceTypes.DEV: 8>, <SBInterfaceTypes.S3: 16>, <SBInterfaceTypes.T3: 48>]
<SBInterfaceTypes.T3: 48> but should be 52.

32 | 4 | 16
= 52

Using T3 = PROD| S3 | auto() works as expected though.

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