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

App decorator methods (e.g., action, command) have incorrect return type annotation #459

Closed
chrisbouchard opened this issue Sep 7, 2021 · 2 comments · Fixed by #460
Closed
Assignees
Labels
area:async area:sync bug Something isn't working
Milestone

Comments

@chrisbouchard
Copy link
Contributor

chrisbouchard commented Sep 7, 2021

Methods on App that are intended to be used as decorators have an incorrect return type annotation. E.g., for App.command,

def command(
    self,
    command: Union[str, Pattern],
    matchers: Optional[Sequence[Callable[..., bool]]] = None,
    middleware: Optional[Sequence[Union[Callable, Middleware]]] = None,
) -> Optional[Callable[..., Optional[BoltResponse]]]:

As written, this is actually the return type for the __call__ function (the function returned by command). I believe the actual return type annotation for this method should be

-> Callable[..., Optional[Callable[..., Optional[BoltResponse]]]]

I believe this same bug exists for all decorator methods. I've just used command as an example because it's the one I was using in my code.

Reproducible in:

pip freeze | grep slack
python --version
sw_vers && uname -v # or `ver`

The slack_bolt version

slack-bolt @ file:///home/chris/.cache/pypoetry/artifacts/07/a4/dc/0ff1b9
e40910182628c62f696f06a685006e9bbebde8e0fbbf8dc2aa6c/slack_bolt-1.9.0-py2
.py3-none-any.whl
slack-sdk @ file:///home/chris/.cache/pypoetry/artifacts/54/72/e4/1b7d076
acf9c2a6c8175154452e38c8cd43f48c7f2c987c804b32c8a8c/slack_sdk-3.10.1-py2.
py3-none-any.whl

The mypy version

mypy @ file:///home/chris/.cache/pypoetry/artifacts/36/49/09/f6ff69bf72a4
3d56fd882450780491cf84523aa3cb39b1d0e3f2c6c9a4/mypy-0.910-cp39-cp39-manyl
inux2010_x86_64.whl

Python runtime version

Python 3.9.6

OS info

(I ran uname -av because neither of the commands listened work on Fedora.)

Linux **** 5.13.12-200.fc34.x86_64 #1 SMP Wed Aug 18 13:27:18 UTC 2021 x86
_64 x86_64 x86_64 GNU/Linux

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., setup.py))

  1. Create an App instance called app.
  2. Register a listener:
    app.command(COMMAND_NAME)(listener_function)
  3. Run mypy on the code.

Expected result:

mypy returns no type errors.

Actual result:

mypy returns an error for the line registering the listener function.

error: "None" not callable

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@seratch seratch added this to the 1.9.1 milestone Sep 7, 2021
@seratch seratch added area:async area:sync bug Something isn't working labels Sep 7, 2021
@seratch seratch self-assigned this Sep 7, 2021
@seratch
Copy link
Member

seratch commented Sep 7, 2021

Hi @chrisbouchard, thanks for taking the time to report this issue! And you are right that those type hints are not correct. We'll fix this issue in the next release.

@chrisbouchard
Copy link
Contributor Author

Thank you for addressing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:async area:sync bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants