-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Generic types that use ParamSpec aren't callable #11846
Comments
Types are callable in the general case: https://mypy-play.net/?mypy=latest&python=3.10&gist=a18ffb3451fb8341f3f89341edebab5b I'm not sure what's going on here; I suspect some weird interaction with ParamSpec, though. |
Maybe due to existence of self? In such cases, we need to use |
@achimnol How would you use |
Hm... I think I'm wrong about using The following code is well accepted and type-checked by mypy, def myfun(x: int) -> str:
return 'b' + str(x)
print('a' + custom_vjp(myfun, x=0)(123)) # accepted
print(1 + custom_vjp(myfun, x=0)(123)) # rejected but here the problem seems to lie in the type inference of pyright accepts your example while mypy shows an error as you reported. |
Though, your example may be converted to: def custom_vjp(func: Callable[P, R], x: int = 0) -> Callable[P, R]:
def inner(*args: P.args, **kwargs: P.kwargs) -> R:
return func(*args, **kwargs)
return inner
partial(custom_vjp, x=0) # accepted & type-checked well unless you are using other states and methods in |
OK, investigated a bit and it looks like it's due to ParamSpecs not being treated right in subtype checking: I believe this is due to a missing special case in subtype checking here ( Lines 333 to 362 in ef43416
Compare what will happen for Lines 220 to 221 in ef43416
This might be an easy first PR for someone wanting that :P (just check that |
I ran into this in some code I was writing myself and can probably fix it (once my existing mypy PR gets merged, I really don't want to have to think about multiple PRs at once). If someone beats me to it, great! |
Original example works on master, likely fixed by #15837 |
The text was updated successfully, but these errors were encountered: