I have the following callable Protocol
:
class OnStarted(Protocol):
def __call__(self, kwargs: Dict[str, Any]) -> Optional[Dict[str, Any]]: ...
that I want to assign a default function, which I did like this:
def foo(on_started: OnStarted = lambda _: {}):
pass
but MyPy isn't happy with it and complains with this error:
foo.py:172: error: Incompatible default for argument "on_started" (default has type "Callable[[Any], Dict[<nothing>, <nothing>]]", argument has type "OnStarted") [assignment]
foo.py:172: note: "OnStarted.__call__" has type "Callable[[Arg(Dict[str, Any], 'kwargs')], Optional[Dict[str, Any]]]"
How can I fix that so that on_started
has a default value and MyPy doesn't error?