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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click 8.0 does not support mypy's no_implicit_reexport #1879

Closed
tucked opened this issue May 11, 2021 · 9 comments 路 Fixed by #1887
Closed

Click 8.0 does not support mypy's no_implicit_reexport #1879

tucked opened this issue May 11, 2021 · 9 comments 路 Fixed by #1887
Labels
Milestone

Comments

@tucked
Copy link

tucked commented May 11, 2021

Looks like 8.0.0 started shipping type annotations (yay!): 0103c95

Something doesn't seem to be clicking (no pun intended 馃榿) with mypy , though:

error: Name 'click.Context' is not defined
error: Name 'click.Option' is not defined
error: Module has no attribute "command"; maybe "Command"?
error: Module has no attribute "option"; maybe "Option"?
error: Module has no attribute "IntRange"
error: Module has no attribute "Choice"
error: Name 'click.Context' is not defined
error: Module has no attribute "argument"; maybe "Argument"?
error: Module has no attribute "pass_context"
error: Module has no attribute "secho"; maybe "echo"?
error: Module has no attribute "echo"; maybe "secho"?

Anyone else seeing this or know what's up?

@davidism
Copy link
Member

Please provide a minimal reproducible example. It's not clear that this is an issue with Click vs MyPy vs typeshed.

@tucked
Copy link
Author

tucked commented May 11, 2021

I'll work on that...

As another datapoint, I've asked about this on the Mypy Gitter and got this response:

That __init__.py needs from .x import Y as Y for mypy to recognize the re-exports I think

@tucked
Copy link
Author

tucked commented May 11, 2021

# foo.py
import click

def foo(option: click.Option) -> None:
    pass
python3 -m venv venv
venv/bin/pip install --upgrade 'click>=8' mypy
venv/bin/mypy --strict foo.py
foo.py:3: error: Name 'click.Option' is not defined
Found 1 error in 1 file (checked 1 source file)

@tucked tucked changed the title Wonky mypy results Wonky mypy --strict results May 11, 2021
@tucked
Copy link
Author

tucked commented May 11, 2021

I've updated the title because that repro 鈽濓笍 doesn't seem to happen without --strict.

@davidism
Copy link
Member

You'll probably want to report this to mypy, as I have absolutely no idea how to address it. Need some typing experts to look at it.

@JelleZijlstra
Copy link

This is about the --no-implicit-reexport flag: https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport. Click's __init__.py has a bunch of lines like from .module import Name. With that flag on, mypy doesn't treat such names as being re-exported, and to make it accept the code you need to do from .module import Name as Name.

That said this seems a bit too strict in this case, so maybe mypy should change its behavior to be more permissive here.

@davidism
Copy link
Member

Thanks @JelleZijlstra, I'll close this for now as it seems to be a project config issue, not an issue with our types.

@tucked
Copy link
Author

tucked commented May 11, 2021

Workaround is to pin click<8 so that mypy falls back to using typeshed.

@davidism
Copy link
Member

davidism commented May 11, 2021

This is a configuration you add to your own project, not something we will change.

[mypy-click]
no_implicit_reexport = False

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.

3 participants