wearepal / data-science-types

Mypy stubs, i.e., type information, for numpy, pandas and matplotlib
Apache License 2.0
202 stars 51 forks source link

check_all.sh fails when using a project level virtual environment #167

Open TheCleric opened 4 years ago

TheCleric commented 4 years ago

I am in the process of fleshing out a few pyi files with the definitions from Pandas.

My normal process for python development is to create a virtual environment on the root level of each project (to keep code segregated), like so:

python -m venv venv && . venv/bin/activate && pip install --upgrade pip && pip install -e .[dev]

After updating the pyi files and adding tests, everything looks okay, right up to the end of check_all.sh. When it is running the line && mypy tests \ this causes it to find a LOT (> 900 on my machine) of errors from packages in the venv folder. Sample output:

venv/lib/python3.8/site-packages/mypy/typeshed/stdlib/3/typing.pyi:675: error: Return type becomes "Union[bool, Any]" due to an unfollowed import
venv/lib/python3.8/site-packages/mypy/typeshed/stdlib/3/tkinter/commondialog.pyi:7: error: Function is missing a type annotation for one or more arguments
venv/lib/python3.8/site-packages/mypy/typeshed/stdlib/3/tkinter/commondialog.pyi:8: error: Function is missing a type annotation for one or more arguments
venv/lib/python3.8/site-packages/mypy/typeshed/stdlib/3/_thread.pyi:43: error: Function is missing a type annotation for one or more arguments
venv/lib/python3.8/site-packages/packaging/_typing.py:34: error: Statement is unreachable

Similar lines to those continue for many more lines.

I did notice if I deleted no_silence_site_packages = True this goes away, but not sure the intention behind that setting, so I didn't want to delete it and cause downstream issues.

tmke8 commented 4 years ago

Hmm, we observed something similar here: https://github.com/predictive-analytics-lab/data-science-types/pull/155#issuecomment-681001951 I'm not sure what causes this.

tmke8 commented 4 years ago

Without the setting, mypy doesn't check the type stubs at all.

TheCleric commented 4 years ago

I'm assuming that without the virtualenv that the check_all does not throw these errors? If so, I wonder if this is a mypy issue.

TheCleric commented 4 years ago

As a test I deleted my venv and moved it out of the data-science-types directory, and this still occurred. So it doesn't seem to matter that it was in the module folder.

tmke8 commented 4 years ago

I'm assuming that without the virtualenv that the check_all does not throw these errors? If so, I wonder if this is a mypy issue.

Yes, I don't get any errors from mypy when I run it in my environment (except maybe 1 from the typing module which I can do nothing about).

tmke8 commented 4 years ago

Usually I use conda environments, so maybe it's related to that. I'll try a venv environment.

TheCleric commented 4 years ago

It's hacky, but for now I've changed the line && mypy tests \ to && mypy | grep -v venv \ on my local branch (uncommited). I still get a message that there were > 900 errors, but I only see the ones I actually caused. 😆