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

functools.partial forwards ParamSpec args and kwargs incorrectly #16404

Closed
NeilGirdhar opened this issue Nov 4, 2023 · 3 comments
Closed

functools.partial forwards ParamSpec args and kwargs incorrectly #16404

NeilGirdhar opened this issue Nov 4, 2023 · 3 comments
Labels
bug mypy got something wrong

Comments

@NeilGirdhar
Copy link
Contributor

NeilGirdhar commented Nov 4, 2023

from typing import TypeVar, ParamSpec, Generic, Protocol
from collections.abc import Callable
from functools import partial

V_co = TypeVar("V_co", covariant=True)
P = ParamSpec("P")

class Wrapped(Protocol, Generic[P, V_co]):
  def __call__(self, *args: P.args, **kwargs: P.kwargs) -> V_co:
    raise NotImplementedError

def jit(fun: Callable[P, V_co],
        argnames: str | None = None
        ) -> Wrapped[P, V_co]:
  ...

@partial(jit, argnames='debug')
def some_function(debug: bool = False):
  pass

some_function(debug=False)
# a.py:22: error: Argument "debug" to "__call__" of "Wrapped" has incompatible type "bool"; expected "P.kwargs"  [arg-type]

MyPy 1.6.1 is for some reason exposing "P.kwargs" and demanding it as a parameter!

(PyRight produces no errors.)

May possibly be related to #15215, but this gives a very different error.

@ilevkivskyi
Copy link
Member

Works on master. (It however infers quite imprecise type, but this is because partial is imprecisely typed).

@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2023
@NeilGirdhar
Copy link
Contributor Author

NeilGirdhar commented Nov 4, 2023

@ilevkivskyi Should we leave an issue open regarding inferring a precise type for partial?

@ilevkivskyi
Copy link
Member

There is a separate issue for partial #1484

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