Начиная с этого кода (ни mypy, ниpyright пока не жалуются):
Код: Выделить всё
from typing import Literal, overload
@overload
def test(switch: Literal[True]) -> int: ...
@overload
def test(switch: Literal[False]) -> None: ...
def test(switch: bool) -> int | None:
return 123 if switch is True else None
test_int: int = test(True)
test_none: None = test(False)
Код: Выделить всё
def test(switch: bool, var1: str, var2: float, var3: int) -> int | None:
return 123 if switch is True else None
Подробнее здесь: https://stackoverflow.com/questions/787 ... -signature