8000 Protocol with paramspec decorator returning [Nothing, Nothing] · Issue #16142 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
christianbundy opened this issue Sep 18, 2023 · 1 comment
Closed

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

christianbundy opened this issue Sep 18, 2023 · 1 comment
Labels
bug mypy got something wrong

Comments

@christianbundy
Copy link
Contributor

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
@christianbundy christianbundy added the bug mypy got something wrong label Sep 18, 2023
@christianbundy
Copy link
Contributor Author

Closing as a duplicate of #15827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant
0