Вот мой код:
< pre class="lang-py Prettyprint-override">
Код: Выделить всё
# main.py
from __future__ import annotations
from typing import Optional, overload, Literal
class Animal:
@overload
def foo(self, bar=..., inplace: Literal[False]=...) -> Animal:
...
@overload
def foo(self, bar=..., inplace: Literal[True]=...) -> None:
...
def foo(
self, bar=None, inplace: bool = False
) -> Optional[Animal]:
...
reveal_type(Animal().foo(bar='a'))
reveal_type(Animal().foo(inplace=True))
reveal_type(Animal().foo(inplace=False))
Код: Выделить всё
$ mypy main.py
main.py:8: error: Overloaded function signatures 1 and 2 overlap with incompatible return types
main.py:21: note: Revealed type is 'main.Animal'
main.py:22: note: Revealed type is 'None'
main.py:23: note: Revealed type is 'main.Animal'
Found 1 error in 1 file (checked 1 source file)
Как избежать сигнатур перегруженных функций 1 и 2 перекрываются с несовместимыми типами возврата ошибка в строке 8?
Подробнее здесь: https://stackoverflow.com/questions/664 ... l-argument