Skip to content

Cannot get type hints from python 2 packages #5620

@sqwishy

Description

@sqwishy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions