-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Handling signature overlaps with overloaded definitions and Protocols #8262
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
Comments
This one can be fixed pretty easily be rewriting it so that the definitions don't overlap:
Also, when it is hard to do this, you can often just |
That's an interesting workaround and I appreciate your time, but the problem is more general, isn't it? If we'd change signature, to let's say this one from typing import overload, Callable, List, Tuple
@overload
def itemgetter(item: T) -> Callable[[HasGetItem[T, U]], U]: ...
@overload
def itemgetter(items: List[T]) -> Callable[[HasGetItem[T, U]], Tuple[U, ...]]: ... we're back to square one, aren't we? As of But I guess the real question is if that, for whatever reason, is the expected behavior? (And, just thinking out loud, if this won't-fix, it might be useful to have more specific error code, than |
@zero323 Your example has overlapping signatures, so requiring In your example, consider what happens if we call |
Thank you @JukkaL. |
Let's imagine that we'd like to provide more precise annotations for
operator.itemgetter
. Currently typeshed annotations look like thisThat clearly not very useful. One approach would be to provide a
Protocol
like this:which in isolation works pretty well
However, when plugged into
itemgetter
annotations (mypy 0.770+dev. 7055725)the whole thing fails with
This is relatively generic pattern in functional interfaces and it would be great if there was some way to express it.
Related to #4020
example.txt
The text was updated successfully, but these errors were encountered: