Skip to content

Protocol with paramspec decorator returning [Nothing, Nothing] #16142

@christianbundy

Description

@christianbundy

Bug Report

I have a decorator that wraps a function, so the inputs are both Callable[Params, Return], but I want to change the callable type so that it only accepts functions with a kwargs called foo. I've written the code that looks right, and I can get it to work in some contexts, but when I use it as a wrapper I get an error message.

To Reproduce

from typing import ParamSpec, TypeVar, Protocol

P = ParamSpec("P")
R = TypeVar("R", covariant=True)


class Wrapped(Protocol[P, R]):
    def __call__(self, *args: P.args, foo: int, **kwargs: P.kwargs) -> R:
        ...


def decorator(f: Wrapped[P, R]) -> Wrapped[P, R]:
    return f


@decorator
def foo(foo: int) -> str:
    return "foo"

https://mypy-play.net/?mypy=master&python=3.11&flags=strict&gist=5293d80b80d20f229649788d1c36f3b2

Expected Behavior

This should type check.

Actual Behavior

main.py:16: error: Argument 1 to "decorator" has incompatible type "Callable[[int], str]"; expected "Wrapped[Never, Never]"  [arg-type]

Your Environment

  • Mypy version used: master 9b91524
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions