Skip to content

Enum.value inferred as tuple[Literal[..]] #11270

@hansmaad

Description

@hansmaad

Enum value with a trailing comma is reported as a 1-tuple, but it's str and runtime.

class BodyType1(str, Enum):
    Text = "text",
    Html = "html",

class BodyType2(str, Enum):
    Text = "text"
    Html = "html"

body_type_1: str = BodyType1.Text.value
body_type_2: str = BodyType2.Text.value

print(type(body_type_1))
print(type(body_type_2))

The BodyType example is taken from Graph SDK https://github.com/microsoftgraph/msgraph-sdk-python/blob/main/msgraph/generated/models/body_type.py
To my knowledge values separated with comma will all be passed to init (https://docs.python.org/3/library/enum.html#enum.Enum.__init__).
Here Text = "text", should be equivalent to str("text",).

$ pyright --version
pyright 1.1.408

$ pyright test.py
error: Type "tuple[Literal['text']]" is not assignable to declared type "str"
    "tuple[Literal['text']]" is not assignable to "str" (reportAssignmentType)

$ python --version
Python 3.13.7

$ python test.py
<class 'str'>
<class 'str'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions