pyright icon indicating copy to clipboard operation
pyright copied to clipboard

Regression: false negative of `reportArgumentType` in decorated functions

Open pinterior opened this issue 1 month ago • 2 comments

Describe the bug

In decorated functions, reportArgumentType is not reported in certain situations.

Code or Screenshots

# pyright: strict

import functools
from collections.abc import Callable

def deco[**P, R](f: Callable[P, R]):
    @functools.wraps(f)
    def wrapper(*args: P.args, **kwargs: P.kwargs):
        return f(*args, **kwargs)
    return wrapper

@deco
def g(x: int) -> int:
    ...

@deco
def f():
    t = ""
    t = g(t)
    return t
$ npx [email protected] pp.py 
pp.py
  pp.py:19:11 - error: Argument of type "Literal['']" cannot be assigned to parameter "x" of type "int" in function "__call__"
    "Literal['']" is not assignable to "int" (reportArgumentType)
1 error, 0 warnings, 0 informations
$ for v in $(seq 409 414) ; do npx [email protected].$v pp.py ; done
0 errors, 0 warnings, 0 informations
0 errors, 0 warnings, 0 informations
0 errors, 0 warnings, 0 informations
0 errors, 0 warnings, 0 informations
0 errors, 0 warnings, 0 informations
0 errors, 0 warnings, 0 informations

VS Code extension or command-line

command-line tool, >=1.1.409

pinterior avatar Oct 26 '26 15:10 pinterior

#11807 already exists to fix is the problem.

pinterior avatar Oct 26 '26 16:10 pinterior

Yeah the regression introduced a check that results in a self-referential assignment being marked as incomplete. That is what t = g(t) hits.

#11936 is related but the inverse scenario: the isIncomplete flag doesn't get carried into cyclic contexts, so partial types get cached as final.

Pyright probably has more places where incompleteness is handled incorrectly.

crypt0lith avatar Oct 27 '26 18:10 crypt0lith