python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.54k stars 2.84k forks source link

No such file or directory error when installing types with mypy #16767

Open jakecyr opened 10 months ago

jakecyr commented 10 months ago

Bug Report

When running the command poetry run mypy --config-file pyproject.toml in GitLab CI, MyPy starts installing types as expected, but then throws an error:

mypy: can't read file '/root/.cache/pypoetry/virtualenvs/our-package-d4xTn211-py3.10/lib/python3.10/site-packages//google': No such file or directory

Expected Behavior

I would expect MyPy to install the required types and run the static analysis check.

Actual Behavior

Installing collected packages: types-PyYAML, types-pytz, types-PyMySQL, urllib3, types-protobuf, pycparser, types-requests, cffi, cryptography, types-pyOpenSSL, types-redis
  Attempting uninstall: urllib3
    Found existing installation: urllib3 1.26.18
    Uninstalling urllib3-1.26.18:
      Successfully uninstalled urllib3-1.26.18
Successfully installed cffi-1.16.0 cryptography-41.0.7 pycparser-2.21 types-PyMySQL-1.1.0.1 types-PyYAML-6.0.12.12 types-protobuf-4.24.0.20240106 types-pyOpenSSL-23.3.0.20240106 types-pytz-2023.3.1.1 types-redis-4.6.0.20240106 types-requests-2.31.0.20240106 urllib3-2.1.0
[notice] A new release of pip is available: 23.3.1 -> 23.3.2
[notice] To update, run: pip install --upgrade pip
mypy: can't read file '/root/.cache/pypoetry/virtualenvs/our-package-d4xTn211-py3.10/lib/python3.10/site-packages//google': No such file or directory
Installing missing stub packages:
/root/.cache/pypoetry/virtualenvs/our-package-d4xTn211-py3.10/bin/python -m pip install types-PyMySQL types-PyYAML types-protobuf types-pytz types-redis types-requests

Your Environment

This error occurs when running the mypy command in GitLab CI.

jakecyr commented 10 months ago

It seemed that my previous pipeline jobs that were succeeding started failing so I look at the versions of the typing packages being installed and noticed these were updated since (working versions are below):

types-protobuf = "4.24.0.4"
types-pyopenssl = "23.3.0.0"
types-redis = "4.6.0.11"

Locking the versions to the versions listed above fixed the error. I'm not sure what the issue is with the new typing packages, but it seems either mypy is pulling in incompatible versions or the there is a bug in latest version of one of the packages.

odimko commented 10 months ago

@jakecyr thanks for your comment! it helped a lot.

waiting until this is fixed now https://github.com/python/typeshed/issues/11254

getim commented 10 months ago

We ran into this as well and I drilled down into mypy since yesterday:

I'm just laying this out here because I'm now unsure which component is wrong exactly. The runtime_path assignment can check if dir_chain is empty? Should exists_case be fixed to correctly handle the trailing slash? Both seem to fix the issue from my tests.

Edit: I guess my comment is more about the fact that mypy could handle this better, even if the linked typeshed issue gets fixed.

hauntsaninja commented 10 months ago

@getim thanks for looking into it! While typeshed will need to be fixed, let's remove trailing slash in exists_case — seems less of a sharp edge and matches os.path.exists better. Interested in opening a PR?

getim commented 10 months ago

@hauntsaninja Sounds good, see here