[issue36555] PEP484 @overload vs. str/bytes

Guido van Rossum report at bugs.python.org
Wed Apr 10 16:27:59 EDT 2019


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

> Mypy already takes first overload for ambiguous arguments.

This is true, but it requires that the return types match (covariantly, IIUC) for the overlapping types. So you can have

@overload
def foo(x: int) -> int: ...
@overload
def foo(x: float) -> float: ...

But you can't have

@overload
def foo(x: int) -> str: ...
@overload
def foo(x: float) -> float: ...

(and the docs explain why -- search for "unsafe_func").

----------

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


More information about the Python-bugs-list mailing list