Description
This is a residue of #2634 (comment)
This snippet causes an error when using --strict-optional
:
def f(a: Callable[..., None] = lambda *a, **k: None): pass
Error:
__tmp__.py:7: error: Incompatible types in assignment (expression has type Callable[[StarArg(Any), KwArg(Any)], None], variable has type Callable[..., None])
However this snippet is fine -- the only difference being that the return type is not None
:
def f(a: Callable[..., int] = lambda *a, **k: 0): pass
So @elazarg's claim "it's not about the the parameters but about the return type" is incorrect here.
And yes, this did break one place in our codebase. As a workaround I am putting cast(Callable, ...)
around the lambda
expression:
def f(a: Callable[..., None] = cast(Callable, lambda *a, **k: None)): pass