microsoft / pyright

Static Type Checker for Python
Other
13.21k stars 1.42k forks source link

Decorator reported as untyped when unknown type appears #8298

Closed hmc-cs-mdrissi closed 3 months ago

hmc-cs-mdrissi commented 3 months ago

Describe the bug

from collections.abc import Callable
from typing import TypeVar

from lib import Node

T = TypeVar("T")

Callback = Callable[[T], None]

def dec(*x: str) -> Callable[[Callback[T]], Callback[T]]:
    ...

@dec("")
def foo(x: Node):
    ...

lib is intentionally an unknown name as bug is specific to function with Unknown annotation (any untyped library in real use case).

This code produces an error recently of,

Untyped function decorator obscures type of function

But if I change Node to object the code type checks fine. The decorator is fully annotated, but Unknown in function confuses it somehow.

Other strange thing is this issue requires type alias Callback. If I inline alias the error goes away.

VS Code extension or command-line pyright 1.1.369

erictraut commented 3 months ago

This is included in pyright 1.1.370