Code: Select all
from typing import overload, Literal
@overload
def x(a: int = 5, t: Literal[True] = True, b: int = 5) -> int: ...
@overload
def x(a: int = 5, t: Literal[False] = False, b: int = 5) -> str: ...
def x(a: int = 5, t: bool = True, b: int = 5) -> int | str:
if t:
return 5
return "asd"
< /code>
Aber MyPy erhöht: < /p>
Fehler: Überlastete Funktionssignaturen 1 und 2 Überlappung mit nicht kompatiblen Rückgabetypen < /p>
< /blockquote>
Angenommen, das ist, dass X (). Falsch
Code: Select all
x()
[*]
Code: Select all
x(t=True)
[*]
Code: Select all
x(t=False)