-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Documented @overload failes in non-stub file with --strict #9633
Comments
You should annotate the implementation. The example in the typing docs should perhaps also add an annotation, but that's an issue for the CPython repo, not for mypy. |
Mypy also errors when you annotate the implementation. from typing import overload
@overload
def utf8(value: None) -> None: ...
@overload
def utf8(value: bytes) -> bytes: ...
@overload
def utf8(value: str) -> bytes:
pass
|
That example has no implementation (as the error message says). It may be better to ask for help at https://gitter.im/python/typing. |
Even if you provide an implementation you get the same error message - playground. from typing import overload
@overload
def utf8(value: None) -> None: ...
@overload
def utf8(value: bytes) -> bytes: ...
@overload
def utf8(value: str) -> bytes:
if value is None:
return None
return b''
|
Bug Report
The documentation for
typing.overload
describes how to use overloads. However when used with--strict
the final, untyped, function errors. Support fortyping.overload
in a non-stub file has been discussed in #72 and #1136, and it looks like the documentation should work fine.To Reproduce
Here is a playground for easy viewing.
example.py
Overall
I don't think any harm will come if I silence the error with
# type: ignore
. However I've been really confused why it's not been working and I don't like using# type: ignore
if possible. This has meant that I have opted to not use it in the past.I fear erroring on correct usage may cause others to also not use
overload
.The text was updated successfully, but these errors were encountered: