[issue42169] Apparently all documentation on @typing.overload is wrong

Guido van Rossum report at bugs.python.org
Tue Oct 27 13:47:31 EDT 2020


Guido van Rossum <guido at python.org> added the comment:

> The documentation for `typing.overload` says in a non-stub file the last definition shouldn't be typed.

Incorrect. It doesn't say it shouldn't be *typed*, it says it shouldn't be *decorated with @overload*, which is a different thing.

The example is correct, since no annotation is the same as annotating with `Any`.

But with `mypy --strict`, no annotation causes an error, so if you are using that, you have to add *some* annotation (e.g. `Any`).

In your final example, the overloads are not redundant, since only the overloads tell the type checker that the output type corresponds to the input type.

For more information, please see Gitter (linked from the typing home page).

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42169>
_______________________________________


More information about the Python-bugs-list mailing list