You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generic types that use ParamSpec aren't callable #11846
OK, investigated a bit and it looks like it's due to ParamSpecs not being treated right in subtype checking: (*Any, **Any) -> Any should probably be a supertype of an arbitrary P, I think.
I believe this is due to a missing special case in subtype checking here (is_subtype(left=def (*Any, **Any) -> Any, right=ParamSpec)):
This might be an easy first PR for someone wanting that :P (just check that right is ParamSpecType and that left is def (*Any, **Any) -> Any, I believe?)
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!
Activity
A5rocks commentedon Dec 26, 2021
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.
[-]Types aren't callable?[/-][+]Generic types that use ParamSpec aren't callable[/+]achimnol commentedon Dec 27, 2021
Maybe due to existence of self? In such cases, we need to use
typing.Concatenateintroduced in Python 3.10, but mypy does not yet support it.NeilGirdhar commentedon Dec 27, 2021
@achimnol How would you use
Concatenatehere?achimnol commentedon Dec 28, 2021
Hm... I think I'm wrong about using
Concatenatehere.The following code is well accepted and type-checked by mypy,
but here the problem seems to lie in the type inference of
functools.partialagainst the class constructor.pyright accepts your example while mypy shows an error as you reported.
achimnol commentedon Dec 28, 2021
Though, your example may be converted to:
unless you are using other states and methods in
custom_vjp.A5rocks commentedon Dec 29, 2021
OK, investigated a bit and it looks like it's due to ParamSpecs not being treated right in subtype checking:
(*Any, **Any) -> Anyshould probably be a supertype of an arbitraryP, I think.I believe this is due to a missing special case in subtype checking here (
is_subtype(left=def (*Any, **Any) -> Any, right=ParamSpec)):mypy/mypy/subtypes.py
Lines 333 to 362 in ef43416
Compare what will happen for
is_subtype(left=typing.Any, right=TypeVar):mypy/mypy/subtypes.py
Lines 220 to 221 in ef43416
This might be an easy first PR for someone wanting that :P (just check that
rightisParamSpecTypeand thatleftisdef (*Any, **Any) -> Any, I believe?)A5rocks commentedon Jan 26, 2022
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!
ilevkivskyi commentedon Aug 16, 2023
Original example works on master, likely fixed by #15837