Skip to content

mypy --strict fails on scripts/packages depending on xarray; __all__ required #3695

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

Closed
aldanor opened this issue Jan 14, 2020 · 3 comments · Fixed by #3703
Closed

mypy --strict fails on scripts/packages depending on xarray; __all__ required #3695

aldanor opened this issue Jan 14, 2020 · 3 comments · Fixed by #3703
Assignees

Comments

@aldanor
Copy link

aldanor commented Jan 14, 2020

Checked this with both 0.14.1 and master branch.

Create foo.py:

from xarray import DataArray

and run:

$ mypy --strict foo.py

which results in

foo.py:1: error: Module 'xarray' has no attribute 'DataArray'
Found 1 error in 1 file (checked 1 source file)

I did a bit of digging trying to make it work, it looks like what makes the above script work with mypy is adding

__all__ = ('DataArray',)

to xarray/__init__.py, otherwise mypy treats those imports as "private" (and is correct in doing so).

Should __all__ be added to the root __init__.py? To any __init__.py in subpackages as well?

@shoyer
Copy link
Member

shoyer commented Jan 15, 2020

I'm a little surprised that mypy cares about __all__. For our __init__.py file, we are actually pretty careful to only define variables that are in xarray's public API, so __all__ was otherwise redundant.

In principle I have no objection to adding this, but it would be nice to if you could dig up a reference that explains mypy's behavior.

@aldanor
Copy link
Author

aldanor commented Jan 15, 2020

@aldanor
Copy link
Author

aldanor commented Jan 16, 2020

Any thoughts?

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

Successfully merging a pull request may close this issue.

3 participants