-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Docs: show how to @overload function annotations in user code #2792
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
Conversation
The docs say `@override` doesn't work in user code, but it seems to work in mypy 0.470. The update may be waiting on python#2603, but that PR does not seem to include doc updates, so feel free to put this patch in that PR.
Hm, it doesn't actually work yet AFAICT. The example you give produces an error for me:
So we're still waiting for #2603. Thanks for the contribution though! Once that is in, this will be very helpful. |
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.
Just two small comments.
(By the way this is no more blocked.)
|
||
.. code-block:: python | ||
|
||
# This is a stub file! | ||
class Seq(Generic[T], Sequence[T]): |
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.
Generic[T]
here and below are redundant.
Now if we import ``abs`` as defined in the above library stub, we can | ||
write code like this, and the types are inferred correctly: | ||
class Seq(Generic[T], Sequence[T]): | ||
@overload # These are just for the type checker, and overwritten by the real implementation |
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.
Such long comments will look a bit ugly on readthedocs
. I would recommend wrapping them or shortening to approx. 80 chars.
OK, I can merge once you approve it. |
Is it worth adding the information about the order of
but I'm not sure if it's official or undocumented feature; and also whether it's the entire signature needs to be "narrower" or just the argument or return type. |
Pardon my intervention, I'm superseding this with PR #3159. |
The docs say
@override
doesn't work in user code, but it seems to work in mypy 0.470.The update may be waiting on #2603, but that PR does not seem to include doc updates,
so feel free to put this patch in that PR.