UnionType not assignable to TypeForm
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
Pyright currently rejects assigning a `UnionType` to a `TypeForm`. Contrived example:
```python
from typing_extensions import TypeForm
unparameterized: TypeForm = object | None
parameterized: TypeForm[object] = object | None
```
Output:
```none
main.py
main.py:3:29 - error: Type "UnionType" is not assignable to declared type "TypeForm[Unknown]"
"UnionType" is not assignable to "TypeForm[Unknown]" (reportAssignmentType)
main.py:4:35 - error: Type "UnionType" is not assignable to declared type "TypeForm[object]"
"UnionType" is not assignable to "TypeForm[object]" (reportAssignmentType)
2 errors, 0 warnings, 0 informations
```
This appears to be the root cause of #10793 and [this Stack Overflow question](https://stackoverflow.com/questions/79966645/pyright-fails-parsing-typeform-for-unions-with-embedded-containers). Tested with the pyright CLI (v1.1.411).
Contributor guide
Research direction
Start by reproducing the examples in main.py with the pyright CLI version 1.1.411, then trace how assignments involving TypeForm and UnionType are checked. Done means both the unparameterized and parameterized examples are accepted without the reported assignment errors.
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
- 45/100