pyright
pyright copied to clipboard
Regression: false negative of `reportArgumentType` in decorated functions
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
#11807 already exists to fix is the problem.
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.