microsoft / microsoft/pyright

Type "Shape[int]" is not assignable to declared type "Shape[int]"

Open
#10,466 3 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

```py
class Shape[*Ts](tuple[*Ts]): ...

reveal_type(Shape([42]))
s1: Shape[int] = Shape([42])
```

reports

- ```
Type of "Shape([42])" is "Shape[int]"
```
- ```
Type "Shape[int]" is not assignable to declared type "Shape[int]"
"Untitled.Shape" is not assignable to "Untitled.Shape"
Type parameter "Ts@Shape" is invariant, but "int" is not the same as "*tuple[int]" (reportAssignmentType)
```

which is... odd

[playground](https://pyright-play.net/?pyrightVersion=1.1.400&pythonVersion=3.14&strict=true&code=MYGwhgzhAEDKAWYAOBTA2gKgCoQLoAoAXAVyRHWzwEoAuaAOkYCgmAnFANxTBAH1CAnqnwJkKfGgAsAJlxUq0RUoDEcRKjQBLAHaFcTCAEY6ojTr3QAvGrESZcxaoCiddkgD2rQgEEomgObaALYoulhCKExAA)

Contributor guide

Open the contributing guide

Research direction

Start with the linked playground reproduction using Pyright 1.1.400, Python 3.14, and strict mode. Trace how the variadic generic Shape[int] is inferred and then checked against the annotated assignment. Done means the example no longer reports a self-incompatibility while preserving the revealed type.

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
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.