Thanks to visit codestin.com
Credit goes to github.com

Skip to content

False postives when decorating functions with signature that uses ParamSpec within a decoarator #12909

Closed
@PIG208

Description

@PIG208

Bug Report

When using a decorator on the decorated function within the definition of another decorator, mypy reports false positives.

To Reproduce

from typing import Callable, TypeVar
from typing_extensions import ParamSpec, Concatenate

P = ParamSpec("P")
T = TypeVar("T")


def identity(func: Callable[P, T]) -> Callable[P, T]:
    def _wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
        return func(*args, **kwargs)

    return _wrapped


def int_identity(func: Callable[Concatenate[int, P], T]) -> Callable[Concatenate[int, P], T]:
    # identify should preserve the signature of _wrapped
    # error: Argument 1 to "identity" has incompatible type "Callable[[Arg(int, 'number'), **P], T]"; expected "Callable[[Arg(int, 'number'), **P], T]"
    @identity
    def _wrapped(number: int, *args: P.args, **kwargs: P.kwargs) -> T:
        return func(number, *args, **kwargs)

    return _wrapped

Expected Behavior

The code should pass type-check with no errors.

Actual Behavior

Got error:
error: Argument 1 to "identity" has incompatible type "Callable[[Arg(int, 'number'), **P], T]"; expected "Callable[[Arg(int, 'number'), **P], T]"

Your Environment

  • Mypy version used: 0.960
  • Mypy command-line flags: --strict
  • Python version used: Python 3.8.10
  • Operating system and version: WSL2 - Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions