StrEnum not recognized as a string by dictionary update
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
When using update, to update a dictionary, the keys of the dictionary are StrEnum, but pyright complains because it expects a str
**Code or Screenshots**
```python
from enum import StrEnum
class Region(StrEnum):
NORTH = "north"
SOUTH = "south"
EAST = "east"
WEST = "west"
d1 = {Region.NORTH : 3}
d2 = {'one': 1, 'two' : 2}
d2.update(d1)
```
That shows me:
```
WARNING: there is a new pyright version available (v1.1.407 -> v1.1.408).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`
/home/acampove/Tests/pyright/str_enum/test.py
/home/acampove/Tests/pyright/str_enum/test.py:16:1 - error: No overloads for "update" match the provided arguments (reportCallIssue)
/home/acampove/Tests/pyright/str_enum/test.py:16:11 - error: Argument of type "dict[Region, int]" cannot be assigned to parameter "m" of type "Iterable[tuple[str, int]]" in function "update"
"dict[Region, int]" is not assignable to "Iterable[tuple[str, int]]"
Type parameter "_T_co@Iterable" is covariant, but "Region" is not a subtype of "tuple[str, int]"
"Region" is not assignable to "tuple[str, int]" (reportArgumentType)
2 errors, 0 warnings, 0 informations
```
Contributor guide
Research direction
Start with the provided StrEnum and dict.update reproduction, then trace Pyright's handling of dictionary update overloads and StrEnum subtyping. Add or update a regression test if the relevant test location can be found; done means the example is accepted without reportCallIssue errors while existing update checks remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100