Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callables whose return value is ignored #237

Open
Akuli opened this issue Jun 26, 2022 · 3 comments · May be fixed by #412
Open

Callables whose return value is ignored #237

Akuli opened this issue Jun 26, 2022 · 3 comments · May be fixed by #412

Comments

@Akuli
Copy link
Collaborator

Akuli commented Jun 26, 2022

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.

@AlexWaygood
Copy link
Collaborator

AlexWaygood commented Jun 26, 2022

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

I'm starting to wonder if we should split the tool in two: one flake8 plugin for checks which only apply for stubs, another which has typing-related checks for .pyi files and .py files alike.

Or maybe we should just bite the bullet and add the necessary complexity to make the plugin .py-compatible as well, since an increasing number of our checks apply to both file types.

@srittau
Copy link
Collaborator

srittau commented Jun 26, 2022

We could also try to get some of the non-pyi-specific checks accepted into flake8/pyflakes(?).

@AlexWaygood
Copy link
Collaborator

We could also try to get some of the non-pyi-specific checks accepted into flake8/pyflakes(?).

We could try, but I think they would probably be rejected. I think the checks we have here are probably too typing-specific.

There are other plugins that specialise in providing checks for annotations, e.g. https://github.com/sco1/flake8-annotations. The checks https://github.com/sco1/flake8-annotations currently does are pretty basic, though, imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants