Skip to content
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

Positional-or-kw arg considered incompatible with positional-only argument #12525

Open
intgr opened this issue Apr 5, 2022 · 1 comment
Open
Labels
bug mypy got something wrong topic-calls Function calls, *args, **kwargs, defaults topic-protocols

Comments

@intgr
Copy link
Contributor

intgr commented Apr 5, 2022

Bug Report

from typing_extensions import Protocol


class Func(Protocol):
    def __call__(self, __a: int, **kwargs: str) -> None:
        #              ^^^ positional-only arg
        ...
    # Same error when using PEP 570 positional-only syntax:
    # def __call__(self, a: int, /, **kwargs: str) -> None:


def myfunc(a: int, **kwargs: str) -> None:
    pass


f: Func = myfunc

Expected Behavior

In my view this should be allowed. Anyone calling f() promises to pass the 1st argument as positional. And myfunc accepts the 1st argument as positional or kwarg, so it should be considered compatible.

Actual Behavior

Mypy output:

positional_only.py:12: error: Incompatible types in assignment (expression has type "Callable[[int, KwArg(str)], Any]", variable has type "Func")
positional_only.py:12: note: "Func.__call__" has type "Callable[[int, KwArg(str)], Any]"

Your Environment

  • Mypy version used: 0.942
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: 3.10.2
  • Operating system and version: macOS
@intgr intgr added the bug mypy got something wrong label Apr 5, 2022
@AlexWaygood AlexWaygood added topic-protocols topic-calls Function calls, *args, **kwargs, defaults labels Apr 5, 2022
@erictraut
Copy link

I agree this is a false positive. This should be allowed because there is no type safety violation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-calls Function calls, *args, **kwargs, defaults topic-protocols
Projects
None yet
Development

No branches or pull requests

3 participants