Skip to content

bug: spurious "partially unknown" #10850

@bukzor

Description

@bukzor

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:

$ 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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions