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

<nothing> not callable error in Mypy with Click 8.1.0 #2227

Closed
NiklasRosenstein opened this issue Mar 28, 2022 · 5 comments · Fixed by #2233
Closed

<nothing> not callable error in Mypy with Click 8.1.0 #2227

NiklasRosenstein opened this issue Mar 28, 2022 · 5 comments · Fixed by #2233
Labels
Milestone

Comments

@NiklasRosenstein
Copy link

NiklasRosenstein commented Mar 28, 2022

# a.py
import click
@click.command()
def test():
  pass
test()

Run

$ mypy a.py
a.py:9: error: <nothing> not callable
Found 1 error in 1 file (checked 1 source file)

This used to pass with Click 8.0.4

Environment:

  • Python version: 3.10.2
  • Click version: 8.1.0
@davidism
Copy link
Member

Happy to consider a PR that adjusts the type annotations.

@Dreamsorcerer
Copy link

Looking at the code (https://github.com/pallets/click/blob/main/src/click/core.py#L1814), it appears to have been changed to a Union while adding support for not calling the decorator before the function.

As per the mypy documentation, this should be represented with overloads, rather than a union:
https://mypy.readthedocs.io/en/stable/generics.html?highlight=decorator#decorator-factories

gadomski added a commit to stac-utils/stactools that referenced this issue Mar 29, 2022
It broke decorator typing: pallets/click#2227
gadomski added a commit to stac-utils/stactools that referenced this issue Mar 29, 2022
It broke decorator typing: pallets/click#2227
@henryiii
Copy link
Contributor

I think this is the same problem:

This MWE:

import click

@click.group()
def main() -> None:
    pass

@main.command()
def tree() -> None:
    pass

Run with this noxfile:

import nox

@nox.session
@nox.parametrize("click", ["8.0.4", "8.1.0"])
def mypy(session: nox.session, click: str) -> None:
    session.install("mypy==0.942", f"click=={click}")
    session.run("mypy", "--strict", "example.py")

Produces:

$ nox
nox > Running session mypy(click='8.0.4')
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/mypy-click-8-0-4
nox > python -m pip install mypy==0.942 click==8.0.4
nox > mypy --strict example.py
Success: no issues found in 1 source file
nox > Session mypy(click='8.0.4') was successful.
nox > Running session mypy(click='8.1.0')
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/mypy-click-8-1-0
nox > python -m pip install mypy==0.942 click==8.1.0
nox > mypy --strict example.py
example.py:7: error: Untyped decorator makes function "tree" untyped
Found 1 error in 1 file (checked 1 source file)
nox > Command mypy --strict example.py failed with exit code 1
nox > Session mypy(click='8.1.0') failed.
nox > Ran multiple sessions:
nox > * mypy(click='8.0.4'): success
nox > * mypy(click='8.1.0'): failed

I'm guessing this was broken by #2212?

@mdellweg
Copy link

I am wondering if similar type annotations need to be added to click.group() and click.Group.group().

@davidism
Copy link
Member

Click 8.1.1 is now available: https://pypi.org/project/click/8.1.1/

JelleZijlstra added a commit to psf/black that referenced this issue Mar 30, 2022
Click 8.1.1 was released with a fix for pallets/click#2227.
JelleZijlstra added a commit to psf/black that referenced this issue Mar 30, 2022
dhruvmanila added a commit to dhruvmanila/remove-print-statements that referenced this issue Mar 31, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants