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

Fix subtyping between ParamSpecs #15892

Merged
merged 2 commits into from
Aug 17, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #14169
Fixes #14168

Two sings here:

  • Actually check prefix when we should
  • strict_concatenate check should be off by default (IIUC it is not mandated by the PEP)

cc @A5rocks

@@ -6483,7 +6483,7 @@ P = ParamSpec("P")
R = TypeVar("R")

@overload
def func(x: Callable[Concatenate[Any, P], R]) -> Callable[P, R]: ...
def func(x: Callable[Concatenate[Any, P], R]) -> Callable[P, R]: ... # E: Overloaded function signatures 1 and 2 overlap with incompatible return types
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now this error removed in my previous PR is back, LOL.

@github-actions

This comment has been minimized.

@A5rocks
Copy link
Contributor

A5rocks commented Aug 16, 2023

Quick comment since I haven't looked over the code yet:

strict_concatenate check should be off by default (IIUC it is not mandated by the PEP)

My impression (I forgot everything...) is that it's mandated. But now I looked back at the PEP and found this example, which is not allowed by strict concatenate:

def add(f: Callable[P, int]) -> Callable[Concatenate[str, P], None]:

  def foo(s: str, *args: P.args, **kwargs: P.kwargs) -> None:  # Accepted
    pass

[snip]

  return foo                                                   # Accepted

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic makes sense to me. Not entirely sure why you switched the default but changing that's fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice you use Protocol instead of Generic. While this should not care about that (obviously), mind adding one or shifting a test case over?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add one test case.

@ilevkivskyi
Copy link
Member Author

Not entirely sure why you switched the default but changing that's fine.

Without it one test case fails. Also it is a deviation from the PEP, so probably should not be on by default. (Btw I noticed in one test case you added: "this is one noticeable deviation from PEP but I believe it is for the better", so I guess it was an intentional decision).

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/core.py:1799: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]

@ilevkivskyi ilevkivskyi merged commit b3d0937 into python:master Aug 17, 2023
17 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-paramspec-subtyping branch August 17, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants