`list[str]` is assignable to `list[int | Any]`, but shouldn't be
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
[Playground](https://pyright-play.net/?pythonVersion=3.13&strict=true&locale=en&enableExperimentalFeatures=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCCKcAsAFDkAmApsFMABQAeAXFADZIDOMA2qvgA%2BhYgF0AlC3JQZUBAEMuXclVpQ0zNpx68eICVLKz6zcUA):
```python
from typing import Any
def f(x: list[int | Any]):
pass
def g(x: list[str]):
f(x)
```
Pyright allows this, but I would expect it to error, since there is no materialization of `list[int | Any]` that is a supertype of `list[str]`. Mypy errors here correctly.
Use case: Dicts support `.update()` with keyword args, like `{}.update(a=3)`. Currently typeshed allows this only if the key type is `str`. I got an error on a dict with keys of type `str | int`, so I tried to change typeshed to use `str | Any` as the required key type here. But now pyright allows `.update()` with kwargs even if the key type doesn't overlap with `str`.
Contributor guide
Research direction
Start with the linked Pyright Playground reproduction and compare its result with the stated mypy behavior for list[str] passed to list[int | Any]. Trace the assignability rules involved in this call and add or update a regression test for the example; done means Pyright rejects the incompatible list assignment without breaking valid Any-related cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100