bug: spurious "partially unknown"
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
I don't understand this bug at all, but I can tell you how to reproduce it, and I think it's clearly a bug.
Setup:
```console
$ tail -vn99 demo*
==> demo_typed.py <==
from __future__ import annotations
from typing import TypeVar
J = TypeVar("J", bound="JSON")
JSONObjectOf = dict[str, J]
JSON = str | JSONObjectOf["JSON"]
JSONObject = JSONObjectOf[JSON]
==> demo.py <==
from demo_typed import JSON
from demo_typed import JSONObjectOf
def identity(json: JSONObjectOf[JSON]):
return json
==> demo0.py <==
import demo_typed
def identity0(json0: demo_typed.JSONObjectOf[demo_typed.JSON]):
return json0
==> demo1.py <==
from demo_typed import JSON
from demo_typed import JSONObjectOf
def identity1(json1: JSONObjectOf[JSON]):
return json1
==> demo2.py <==
from demo_typed import JSONObject
def identity2(json2: JSONObject):
return json2
==> demo3.py <==
import demo_typed
def identity3(json3: demo_typed.JSONObject):
return json3
```
**expected behavior**:
```
$ pyright demo0.py demo2.py | sed 's#'"$PWD/"'#./#g'
0 errors, 0 warnings, 0 informations
```
**actual behavior**:
```
$ pyright demo2.py demo0.py | sed 's#'"$PWD/"'#./#g'
./demo0.py
./demo0.py:4:5 - error: Return type, "dict[str, str | Unknown]", is partially unknown (reportUnknownParameterType)
./demo0.py:4:15 - error: Type of parameter "json0" is partially unknown
Parameter type is "dict[str, str | Unknown]" (reportUnknownParameterType)
./demo0.py:4:46 - error: Type of "JSON" is partially unknown
Type of "JSON" is "type[str] | Unknown" (reportUnknownMemberType)
./demo0.py:5:12 - error: Return type, "dict[str, str | Unknown]", is partially unknown (reportUnknownVariableType)
./demo2.py
./demo2.py:4:5 - error: Return type, "dict[str, str | Unknown]", is partially unknown (reportUnknownParameterType)
./demo2.py:4:15 - error: Type of parameter "json2" is partially unknown
Parameter type is "dict[str, str | Unknown]" (reportUnknownParameterType)
./demo2.py:5:12 - error: Return type, "dict[str, str | Unknown]", is partially unknown (reportUnknownVariableType)
7 errors, 0 warnings, 0 informations
```
NOTE:
* the only difference between the commands is the ordering of files.
* the only difference between files is the details of *how* objects are imported.
**VS Code extension or command-line**
```
$ pyright --version
pyright 1.1.404
$ cat pyproject.toml
[tool.pyright]
reportUnknownParameterType = "error"
```
Contributor guide
Research direction
Reproduce the issue using demo_typed.py and demo.py through demo3.py with pyright 1.1.404, running the two commands with reversed file order. Compare the import forms and diagnostics, then verify that both command orders produce zero errors, warnings, and informations as expected.
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
- 35/100