-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
TypeVars should be allowed to be the same #7864
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
No, they shouldn't. The default value isn't part of the function API, so calls with omitted second argument will be either unsafe or underspecified. For example, imagine you have an entry in a stub: def _map2(queue: Iterable[B], function: Callable[[B], A] = ...) -> Iterable[A]: ... assuming this type, what should be the inferred type of @overload
def _map2(queue: Iterable[A]) -> Iterable[A]: ...
@overload
def _map2(queue: Iterable[B], function: Callable[[B], A]) -> Iterable[A]: ...
def _map2(queue, function=identity):
# implementation goes here
... Surprisingly, this often comes as a source of confusion (I have seen half a dozen issues about this), so I think we should document this (probably in the section "Common issues"). |
thank you for the clarifications! It might be helpful if mypy/the typing module provide examples of some more 'complex' functions (map, zip, function decorators, callables which have a few typed arguments and arbitrarily many Any arguments). |
First time contributor here. If no one else is expanding the docs, I'd like to take a stab at it. |
@tz-earl Welcome, please feel free to get started on it! Let me know if you have any questions. |
@ethanhs Thanks a lot for the go-ahead. Just to be sure, it seems that there is an older package overload that has been superceded by the package overloading. Is that right? |
I don't think any packages named |
@JelleZijlstra Thank you! I'm not at all familiar with the @overload decorator, and I missed the reference to the typing package in other comments. |
With respect to For this particular issue, is it more accurate to talk about unconstrained TypeVars rather than unbound? Or is it both? |
I don't think type variable constraints or bounds make a difference here. The explanation would work for all type variables. |
@JukkaL Thanks so much for pointing out that the issue applies to all type variables, regardless of how they are defined. |
Hi, I would like to ask what's the process I should follow to contribute to this issue since the last pull request has some issues that have not been resolved for a long time. |
Two unbound TypeVars
A
andB
can potentially be the same:The introduced default keyword argument leads to the following unexpected error:
error: Incompatible default for argument "function" (default has type "Callable[[A], A]", argument has type "Callable[[B], A]")
I'm using mypy 0.740.
The text was updated successfully, but these errors were encountered: