-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 on function-decorator error #12593
Labels
bug
mypy got something wrong
Comments
This was referenced Apr 15, 2022
I think the main problem is the definition of from typing import Callable, Concatenate, Generic, ParamSpec, Protocol, TypeVar
from typing_extensions import reveal_type
P = ParamSpec("P")
R_co = TypeVar("R_co", covariant=True)
T = TypeVar("T")
class simple_partial(Generic[P, R_co, T]):
"""This version of `partial` can only set one argument and it has to be the first."""
def __init__(self, __func: Callable[Concatenate[T, P], R_co], arg: T):
self.func = __func
self.arg = arg
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R_co:
return self.func(self.arg, *args, **kwargs)
class Wrapped(Protocol[P, R_co]):
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R_co: ...
def jit(flag: bool, f: Callable[P, T]) -> Wrapped[P, T]:
return f
def f(x: int, y: int) -> int:
return x + y
partial_jit = simple_partial(jit, True)
reveal_type(partial_jit) # N: Revealed type is "simple_partial[[f: def (*P.args, **P.kwargs) -> T`-2], Wrapped[P`-1, T`-2], builtins.bool]"
f_wrapped = partial_jit(f)
reveal_type(f_wrapped) # N: Revealed type is "Wrapped[[x: builtins.int, y: builtins.int], builtins.int]"
x = f_wrapped(0, 0)
reveal_type(x) # N: Revealed type is "builtins.int" |
All four original examples work on current master, but some only with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error:
If change to:
error:
If change to:
error:
If change to:
error:
The text was updated successfully, but these errors were encountered: