Skip to content

Incompatible types in assignment with --strict-optional for a: Callable[..., None] = lambda *a, **k: None #2764

@gvanrossum

Description

@gvanrossum

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions