microsoft / microsoft/pyright

`reportUnknownVariableType` sometimes not reported

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

Description

**Describe the bug**

`reportUnknownVariableType` is sometimes not reported.

In the `foo` function below, `r` is revealed (in the mouse-over) as `dict[Unknown, Unknown]`, but the unknown type is not reported.

**Code or Screenshots**

```python
from typing import TypedDict

class TypedDictA(TypedDict):
a: int

class TypedDictB(TypedDict):
r: dict[str, TypedDictA]

def foo() -> TypedDictB:
# no reportUnknownVariableType triggered anywhere here
r = {}
r["r_key"] = {
"a": "a",
}
return {
"r": r,
}

def goo() -> TypedDictA:
p = {}
return p # correctly triggers reportUnknownVariableType
```

pyright playground link:

https://pyright-play.net/?strict=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAqiApgCYAiSAxjAFD1UA2AhgM6uEkXUwCCAFEQRlKNAJQAuWlBlRmEzCjoMW7TsO40AQoK6iYk6bJALSPANqsYIADTqRPXgF16tUsWBRgYMPzFQAWgA%2Be00YLSlZKABiKBQwKBBiHDwAVRQAa3iAdxQANWYQJGYAI0ZiIWJYIrQ0YiTSORQ4bIALeqr2pKMZECgAXigAbwBfHsTzACIQAH0M4jhJpwHh8ajJ5kmFDcmbcbGopJgAVxAUVaj1kC3Evaix%2BndPNB8-QJDKsN5I2QQV0fGR1O5z%2BMSgVFwSRojDg1SQtXqHCSKRg6SyYFyBSKpXKlVoQA

Contributor guide

Open the contributing guide

Research direction

Start by running the linked Pyright playground example with strict mode and compare diagnostics in foo and goo. Trace how the empty dictionary assignment is handled alongside reportUnknownVariableType. Done means the reproduced case reports the unknown variable type consistently and has a regression test covering it.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.