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

Incompatible ParamSpecs are not reported as issue #17766

Open
pfaion opened this issue Sep 13, 2024 · 0 comments
Open

Incompatible ParamSpecs are not reported as issue #17766

pfaion opened this issue Sep 13, 2024 · 0 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate topic-type-variables

Comments

@pfaion
Copy link

pfaion commented Sep 13, 2024

Bug Report

Hey everyone, thanks for all the great work on mypy!

I ran into an issue where mypy does not warn if 2 ParamSpecs need to align but they don't. Hard to describe, so here's an example:

To Reproduce

from collections.abc import Callable
from typing import ParamSpec

P = ParamSpec("P")

def foo(cb1: Callable[P, None], cb2: Callable[P, None]) -> None:
    pass
  
def my_callback_1(x: int) -> None:
    pass

def my_callback_2(x: str) -> None:
    pass

foo(my_callback_1, my_callback_2)

Playground link: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=f2fac01dde7a953c5dec5117428350f6

Expected Behavior

I think mypy should error out on the foo() call since it's not possible to resolve both Callables to a common ParamSpec P.

When I put the same code into VSCode, pylance reports the following error:

Argument of type "(x: str) -> None" cannot be assigned to parameter "cb2" of type "(**P@foo) -> None" in function "foo"
  Type "(x: str) -> None" is not assignable to type "(x: int) -> None"
    Parameter 1: type "int" is incompatible with type "str"
      "int" is not assignable to "str"
Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)

Actual Behavior

mypy does not report any issues:

Success: no issues found in 1 source file

Your Environment

See the playground link above, but when I run into this locally, I have:

  • Mypy version used: mypy 1.11.2 (compiled: yes)
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.12.2
@pfaion pfaion added the bug mypy got something wrong label Sep 13, 2024
@pfaion pfaion changed the title Incompatible ParamSpecs are not causing any issue Incompatible ParamSpecs are not reported as issue Sep 13, 2024
@sobolevn sobolevn added topic-paramspec PEP 612, ParamSpec, Concatenate topic-type-variables labels Sep 15, 2024
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 topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants