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

Regression in 1.2.0: callback protocol with Callable and Concatenate #15065

Closed
Rogdham opened this issue Apr 16, 2023 · 6 comments · Fixed by #15272
Closed

Regression in 1.2.0: callback protocol with Callable and Concatenate #15065

Rogdham opened this issue Apr 16, 2023 · 6 comments · Fixed by #15272
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@Rogdham
Copy link

Rogdham commented Apr 16, 2023

Bug Report

The code below passed with mypy 1.1.1 but not in 1.2.0

To Reproduce

from typing import Concatenate, Callable, ParamSpec, Protocol

P = ParamSpec("P")


class Decorator(Protocol):
    def __call__(self, fct: Callable[Concatenate[str, P], int]) -> Callable[P, int]:
        ...


def foo(value: int) -> Decorator:
    def bar(fct: Callable[Concatenate[str, P], int]) -> Callable[P, int]:
        raise NotImplementedError

    return bar

I haven't been able to strip down any further, it seems that it has something to do with both Callable and Concatenate.

Expected Behavior

No error (as in mypy 1.1.1).

Actual Behavior

The following error is displayed:

issue.py:15: error: Incompatible return value type (got "Callable[[Callable[[str, **P], int]], Callable[P, int]]", expected "Decorator")  [return-value]
issue.py:15: note: "Decorator.__call__" has type "Callable[[Arg(Callable[[str, **P], int], 'fct')], Callable[P, int]]"
Found 1 error in 1 file (checked 1 source file)

Note that I have tried to change the Decorator definition to make fct parameter positional-only:

class Decorator(Protocol):
    def __call__(self, fct: Callable[Concatenate[str, P], int], /) -> Callable[P, int]:
        ...

Which resulted in the error message being even more confusing:

issue.py:15: error: Incompatible return value type (got "Callable[[Callable[[str, **P], int]], Callable[P, int]]", expected "Decorator")  [return-value]
issue.py:15: note: "Decorator.__call__" has type "Callable[[Callable[[str, **P], int]], Callable[P, int]]"
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.2.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.3
@Rogdham Rogdham added the bug mypy got something wrong label Apr 16, 2023
@JelleZijlstra JelleZijlstra added the topic-paramspec PEP 612, ParamSpec, Concatenate label Apr 16, 2023
@Rogdham
Copy link
Author

Rogdham commented Apr 16, 2023

Possibly related to #15037 in which the same error arises without the callback protocol part, like so:

def foo(value: int) -> Callable[[Callable[Concatenate[str, P], int]], Callable[P, int]]:
    def bar(fct: Callable[Concatenate[str, P], int]) -> Callable[P, int]:
        raise NotImplementedError

    return bar
issue.py:10: error: Incompatible return value type (got "Callable[[Arg(Callable[[str, **P], int], 'fct')], Callable[P, int]]", expected "Callable[[Callable[[str, **P], int]], Callable[P, int]]")  [return-value]
Found 1 error in 1 file (checked 1 source file)

@AlexWaygood
Copy link
Member

This bisects to 730ba8a (cc. @A5rocks)

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 16, 2023

This bisects to 730ba8a (cc. @A5rocks)

But #14903 (by @A5rocks) appears to fix the issue! (The PR has not yet been merged, and looks like it still has a few issues for now -- e.g. there's a crash in the latest mypy_primer diff.)

@Rogdham
Copy link
Author

Rogdham commented Apr 16, 2023

Thank you @AlexWaygood for your analysis!

In that case it seems to confirm that it is a duplicate of #15037. But at least it gives @A5rocks an other case (the example from the description of the PR uses a Protocol) to test their PR with!

hauntsaninja pushed a commit that referenced this issue Aug 9, 2023
- Fixes #15037
- Fixes #15065
- Fixes #15073
- Fixes #15388
- Fixes #15086

Yet another part of #14903 that's
finally been extracted!
@abid-mujtaba
Copy link

Looks like the fix was reverted: #15272 (comment). Can we please re-open this issue so that we can keep track of the problem? Thanks.

@A5rocks
Copy link
Contributor

A5rocks commented Aug 10, 2023

Fortunately, the PR it was reverted for fixes this too.

Namely, #15837

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-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
5 participants