-
Notifications
You must be signed in to change notification settings - Fork 23
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
Detect functions that should use ParamSpec
, but don't
#150
Conversation
I'll hold off filing a typeshed PR until folks have had a chance to review. From my perspective, they nearly all look like true positives (though we can't necessarily do much about a lot of them until we can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't checked all output items, but this one looks like a false positive:
./stdlib/functools.pyi:105:9: Y032 Consider using ParamSpec to annotate function "singledispatchmethod.register"
./stdlib/functools.pyi:107:9: Y032 Consider using ParamSpec to annotate function "singledispatchmethod.register"
Link: https://github.com/python/typeshed/blame/master/stdlib/functools.pyi#L105-L107
Agreed -- but one or two false positives are fine, we can just |
After python/typeshed#7050 and python/typeshed#7055 are merged, I don't think any more items output by typeshed-primer will be actionable. The remaining items will all need to be |
Let's see what the remaining damage is. Thanks for working on this! |
[Edited following @JelleZijlstra's comment below] There are 30 remaining entries. Of these:
|
Concatenate can't describe the type of |
Er... could you do something like this?? (But very blue-sky stuff whatever the case; we obviously can't do anything about it for now...) from typing import Any, Callable, Concatenate, Generic, ParamSpec, TypeVar, TypeVarTuple, overload
_P1 = ParamSpec("_P1")
_P2 = ParamSpec("_P2")
_T = TypeVar("_T")
_R_co = TypeVar("_R_co", covariant=True)
_Ts = TypeVarTuple("_Ts")
class partial(Generic[_P1, _P2, _T, _R_co, *_Ts]):
@overload
def __new__(cls, __func: Callable[_P1, _R_co]) -> partial[_P1, _P1, Any, _R_co]: ...
@overload
def __new__(cls, __func: Callable[Concatenate[*_Ts, _P2], _R_co], *args: *_Ts) -> partial[Concatenate[*_Ts, _P2], _P2, Any, _R_co, *_Ts]: ...
@overload
def __new__(cls, __func: Callable[_P1, _R_co], *args: *_Ts, **kwargs: _T) -> partial[_P1, ..., _T, _R_co, *_Ts]: ...
def __call__(self, *args: _P2.args, **kwargs: _P2.kwargs) -> _R_co: ...
func: Callable[_P1, _R_co]
args: tuple[*_Ts]
keywords: dict[str, _T] |
One corner case that I think wouldn't work: if you partial a keyword argument in
I don't think it's possible to express "discard overlapping keyword arguments from |
Anyway... |
cf92ce2
to
ed25ec4
Compare
80d3a8d
to
a724c3b
Compare
I feel the false positive ratio might be too high, as with #135. Also, I feel like we're pretty likely to notice this in code review for new functions. I'm interested in others' opinions too. |
I just pushed an alternative implementation where we only error for Thanks for the discussion everyone! |
No description provided.