Skip to content

Decorator with an explicit positional argument result in the error return-value #13970

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
JonathanPlasse opened this issue Oct 31, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@JonathanPlasse
Copy link

Bug Report

Typed decorator with an explicit positional argument result in the error return-value

To Reproduce

Link to mypy-play

import functools
from typing import Any, Callable, Concatenate, Coroutine, ParamSpec, TypeVar

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


class Client:
    _outgoing_calls_sem: Any = None


def _outgoing_call(
    method: Callable[Concatenate[Client, P], Coroutine[Any, Any, T]]
) -> Callable[Concatenate[Client, P], Coroutine[Any, Any, T]]:
    @functools.wraps(method)
    async def decorated(self: Client, *args: P.args, **kwargs: P.kwargs) -> T:
        if not self._outgoing_calls_sem:
            return await method(self, *args, **kwargs)

        async with self._outgoing_calls_sem:
            return await method(self, *args, **kwargs)

    return decorated

Expected Behavior

I was expecting to be able to use a positional argument for a decorator.

Actual Behavior

Incompatible return value type (
     got "Callable[[Arg(Client, 'self'), **P], Coroutine[Any, Any, T]]",
expected "Callable[[Client, **P], Coroutine[Any, Any, T]]")  [return-value]mypy(error)
This may be because "decorated" has arguments named: "self"mypy(note)

Your Environment

  • Mypy version used: 0.981
  • Mypy command-line flags: --strict it works without it
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10
@JonathanPlasse JonathanPlasse added the bug mypy got something wrong label Oct 31, 2022
@hauntsaninja
Copy link
Collaborator

Needs to be marked as positional only (PEP 570 or double underscores). I improved the error message in #13777. There's also --no-strict-concatenate

@JonathanPlasse
Copy link
Author

Thanks

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

2 participants