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

Type annotations don't work in strict mode with mypy #1426

Closed
gaborbernat opened this issue May 12, 2021 · 5 comments · Fixed by #1434
Closed

Type annotations don't work in strict mode with mypy #1426

gaborbernat opened this issue May 12, 2021 · 5 comments · Fixed by #1434
Assignees
Labels
Milestone

Comments

@gaborbernat
Copy link

Python 3.9.5 + mypy 0.812

# magic.py
from jinja2 import Environment
mypy ./magic.py
Success: no issues found in 1 source file
mypy ./magic.py --strict
magic.py:1: error: Module 'jinja2' does not explicitly export attribute 'Environment'; implicit reexport disabled
Found 1 error in 1 file (checked 1 source file)

Thanks 👍

@davidism
Copy link
Member

You can add the following config to your project to allow Jinja (or other packages) to export from __init__, since it's a very common pattern.

[mypy-jinja2]
no_implicit_reexport = False

See python/mypy#10198 for discussion on changing this behavior.

@gaborbernat
Copy link
Author

gaborbernat commented May 12, 2021

I'd expect that configuration to be part of the upstream project, not the downstream user. Seems it's a choice of the project if they want implicit re-export or not, not the user apps 🤔 All other projects I've been using until now used explicit exports to work around this.

@davidism
Copy link
Member

There is no configuration that upstream projects can provide.

@gaborbernat
Copy link
Author

Hence why most projects use explicit export to not run into this. If you insist on implicit re-export feels like worth creating a PEP and allowing this configurability.

@dquitmann-op
Copy link

Hi @davidism,

is there any release schedule for 3.0.1 fixing this behavior? I do not want to build any pressure, just to know if we should (temporarily) change our pipelines or just can wait for a fixed release coming in the next days.

Thanks very much for the quick fix and your answer in advance!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2021
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