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

Cannot get type hints from python 2 packages #5620

Closed
sqwishy opened this issue Sep 14, 2018 · 4 comments
Closed

Cannot get type hints from python 2 packages #5620

sqwishy opened this issue Sep 14, 2018 · 4 comments

Comments

@sqwishy
Copy link
Contributor

sqwishy commented Sep 14, 2018

In mypy 0.620, there appears to be inconsistent type checking behaviour depending on how you specify the python version. This exists for handling -2 and --python-version 2 arguments and is explained well in issue #5576 and addressed by pull request #5619. However, this inconsistency also occurs with specifying the python version in the a mypy.ini configuration file.

$ mypy --python-version 2.7 pkgb
pkgb/__main__.py:7: error: Argument 1 to "this_is_a_typed_function" has incompatible type "int"; expected "unicode"

That above is expected, but when specifying the version in a config file.

$ echo -e "[mypy]\npython_version: 2.7" | mypy --config-file /dev/stdin pkgb
pkgb/__main__.py:1: error: Cannot find module named 'pkga'

For good measure, I included a python 2 print statement in the test package to ensure it is actually is running under python 2 mode ... The example is included here. Extract the archive; in a Python 2 virtualenv, install the package in the a directory with pip -e a; run mypy on pkgb.


The behaviour seems to come from looking for typing information in different site-packages between the two cases. With --python-version 2.7, a Python 2 interpreter's site-packages are used. With the configuration file, the current interpreter's site-packages are used.

The pull request #5578 was an attempt to resolve this inconsistency by using the Python 2 site-packages in both configurations, but it seems like this broke some things for some folks.

@Michael0x2a
Copy link
Collaborator

Disclaimer: I haven't really been following this issue, so I may be missing some context, but I wonder if this is solvable by just having the people's whose config files broke with #5578 set the python_executable option in addition to the python_version option?

@sqwishy
Copy link
Contributor Author

sqwishy commented Sep 14, 2018 via email

@ilevkivskyi
Copy link
Member

But maybe this should be allowed?

I think I will be fine with this solution (assuming it doesn't break anything else). I just want to have a clear solution for the scenario where PEP 561 stub packages are installed in an interpreter different from the one used to run the code that is being checked (for example in the CI server situation I mention in PR #5578).

@ethanhs I will be very grateful for your advice on this.

@ethanhs
Copy link
Collaborator

ethanhs commented Oct 5, 2018

I think @Michael0x2a's solution is likely optimal here. I will work on a fix for this later.

ethanhs added a commit to ethanhs/mypy that referenced this issue Oct 12, 2018
gvanrossum pushed a commit that referenced this issue Dec 17, 2018
* Remove check that python_[version/executable] agree

* Allow setting python_version/executable from config file

This fixes #5620
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

No branches or pull requests

4 participants