Callables whose return value is ignored

Open
#237 3 comments 2 reactions 0 assignees View on GitHub

@AlexWaygood is already working on this.

Since Jul 10, 2023.

  • #412 by @AlexWaygood — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

No source file, test, or entry point is named. First resolve whether checking ignored callable return values belongs in this stub-focused plugin, then define the intended treatment of Callable[[], None], Callable[[], Any], and Callable[[], object] before implementation and tests.

Written by the indexing model from the issue text.

Description

type-feature
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.

Dominant language
Python
Stars
84
Forks
26
Avg merge
1d 21h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyCQA/flake8-pyi

All issues in PyCQA/flake8-pyi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.