Skip to content

Make enum values final #11919

Description

@joey-laminar

#10852 made it so that boolean values are correctly identified as Literals in an enum. Other values seem to not be:

fromenumimportEnumclassTruth(Enum):
true=Truefalse=FalseclassMyInt(Enum):
a=0b=1classMyStr(Enum):
a="a"b="b"reveal_type(Truth.false.value)
reveal_type(MyInt.a.value)
reveal_type(MyStr.a.value)

Results in:

a.py:15: note: Revealed type is "Literal[False]?"
a.py:16: note: Revealed type is "builtins.int"
a.py:17: note: Revealed type is "builtins.str"

Expected result:

a.py:15: note: Revealed type is "Literal[False]?"
a.py:16: note: Revealed type is "Literal[0]"
a.py:17: note: Revealed type is "Literal['a']"

The enum members themselves (MyInt.a) are correctly identified as final, but their values should be as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions