Skip to content

Unsupported left operand type for | ("auto") #3434

Closed
@lambdalisue

Description

@lambdalisue

Using enum.auto in enum.Flag which has introduced from Python 3.6 cause the following exception

flag.py|8 error| Unsupported left operand type for | ("auto")

with the following code

from enum import Flag, auto


class Color(Flag):
    RED = auto()
    BLUE = auto()
    GREEN = auto()
    WHITE = RED | BLUE | GREEN  " <-- This line.


if __name__ == '__main__':
    assert not bool(Color.RED & Color.BLUE)
    assert not bool(Color.RED & Color.GREEN)
    assert bool(Color.RED & Color.WHITE)

The | operand is supported in enum.Flag so it seems the definition of auto() should be modified for Python 3.6 and over

Ref:
https://docs.python.org/3.6/library/enum.html#flag

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