Код: Выделить всё
from typing import Optional
DEFAULT = object()
# `None` already has meaning.
def spam(ham: Optional[list[str]] = DEFAULT):
if ham is DEFAULT:
ham = ['prosciutto', 'jamon']
if ham is None:
print('Eggs?')
else:
print(str(len(ham)) + ' ham(s).')
< /code>
ошибка: < /p>
Failed (exit code: 1) (2607 ms)
main.py:7: error: Incompatible default for argument "ham" (default has type "object", argument has type "Optional[List[str]]")
Found 1 error in 1 file (checked 1 source file)
< /code>
[list]
[*] Как мне введите хэм < /code> без ошибок в Mypy? или
[*] Какую стратегию мне следует использовать вместо default = object ()
[/list]
Подробнее здесь: https://stackoverflow.com/questions/692 ... he-default