microsoft / pyright

Static Type Checker for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression: ParamSpec are missing when using on args condition check

Hunterlige opened this issue · comments

Describe the bug

When using len() on a ParamSpec args, the variable type will be updated from _P@function.args to tuple[object, ...], causing a reportCallIssue.

Code or Screenshots

from typing import Any, ParamSpec
from collections.abc import Callable
import functools

_P = ParamSpec("_P")


# Does NOT work with pyright>=0.359
def decorator_error(fn: Callable[_P, Any]) -> Any:
    @functools.wraps(fn)
    def wrapper(*args: _P.args, **kw: _P.kwargs) -> Any:
        if len(args) >= 0:
            pass
        return fn(*args, **kw)

    return wrapper


# Does work with pyright>=0.359
def decorator(fn: Callable[_P, Any]) -> Any:
    @functools.wraps(fn)
    def wrapper(*args: _P.args, **kw: _P.kwargs) -> Any:
        return fn(*args, **kw)

    return wrapper

The error is: error: Arguments for ParamSpec "_P@decorator_error" are missing (reportCallIssue)

VS Code extension or command-line

pyright v1.1.361 ❌ (command-line)
pyright v1.1.358 ✅ (command-line)

This is addressed in pyright 1.1.362, which I just published.