Skip to content

Callables whose return value is ignored #237

Open
@Akuli

Description

@Akuli
def foo(callback):
    callback()

There's a few ways to type this function:

def foo(callback: Callable[[], None]) -> None: ...
def foo(callback: Callable[[], Any]) -> None: ...
def foo(callback: Callable[[], object]) -> None: ...

Callable[[], None] is not great, because it doesn't allow you to pass a callback that does return something; that will also work at runtime, and the return value is ignored. When I learned about this, I changed my callbacks to use Callable[[], Any] instead. But Callable[[], object] would be even better.

We could check for this, but does it belong to this tool? This lint isn't really stub-specific.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions