microsoft / microsoft/pyright

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

Open
#11,270 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

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

```python
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

```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal Enum reproducer in the issue and compare Pyright's inferred type with Python's Enum documentation on tuple values and __init__. Done means both trailing-comma and non-comma enum values are accepted as str where runtime behavior confirms that type, with regression coverage added in the relevant Pyright tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.