Repository navigation
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
my minimal reproduction unfortunately requires some third party dependencies but I've tried to make it as self-contained as possible:
To Reproduce
#!/usr/bin/env bash
set -euxo pipefail
rm -rf venv .mypy_cache
cat > pyproject.toml <<EOF
[[tool.mypy.overrides]]
module = ["google.*"]
ignore_missing_imports = true
EOF
cat > t.py <<EOF
from google.cloud import pubsub_v1
from google.cloud import bigtable
EOF
virtualenv -q venv
venv/bin/pip install -q google-cloud-bigtable==2.22.0 google-cloud-pubsub==2.19.0 mypy
venv/bin/mypy t.pyExpected Behavior
I expect it to produce no errors
Actual Behavior
$ bash t.sh
+ rm -rf venv .mypy_cache
+ cat
+ cat
+ virtualenv -q venv
+ venv/bin/pip install -q google-cloud-bigtable==2.22.0 google-cloud-pubsub==2.19.0 mypy
+ venv/bin/mypy t.py
t.py:1: error: Module "google.cloud" has no attribute "pubsub_v1" [attr-defined]
Found 1 error in 1 file (checked 1 source file)what's even stranger is if the bigtable import is commented out it passes:
$ cat t.py
from google.cloud import pubsub_v1
# from google.cloud import bigtable
$ rm -rf .mypy_cache/ && venv/bin/mypy t.py
Success: no issues found in 1 source fileI suspect something to do with namespace packages since google.* is a big bunch of them -- it also has various py.typed files which should have some things typed and others not -- google.cloud.pubsub_v1 does not have one of those (not to be confused with google.pubsub_v1 which does have one):
$ find venv/lib/python3.12/site-packages/google -name py.typed | sort
venv/lib/python3.12/site-packages/google/api_core/py.typed
venv/lib/python3.12/site-packages/google/cloud/_helpers/py.typed
venv/lib/python3.12/site-packages/google/cloud/_http/py.typed
venv/lib/python3.12/site-packages/google/cloud/_testing/py.typed
venv/lib/python3.12/site-packages/google/cloud/bigtable/py.typed
venv/lib/python3.12/site-packages/google/cloud/bigtable_admin/py.typed
venv/lib/python3.12/site-packages/google/cloud/bigtable_admin_v2/py.typed
venv/lib/python3.12/site-packages/google/cloud/bigtable_v2/py.typed
venv/lib/python3.12/site-packages/google/cloud/client/py.typed
venv/lib/python3.12/site-packages/google/cloud/environment_vars/py.typed
venv/lib/python3.12/site-packages/google/cloud/exceptions/py.typed
venv/lib/python3.12/site-packages/google/cloud/obsolete/py.typed
venv/lib/python3.12/site-packages/google/cloud/operation/py.typed
venv/lib/python3.12/site-packages/google/pubsub/py.typed
venv/lib/python3.12/site-packages/google/pubsub_v1/py.typedI don't think the other directories have an effect as I deleted everything but the bigtable and pubsub_v1 directories and it still reproduces
Your Environment
- Mypy version used: 1.10.0
- Mypy command-line flags: see above
- Mypy configuration options from
mypy.ini(and other config files): see above - Python version used: 3.12.2 -- also reproduces on 3.11.x -- didn't try any others
Reacted by Hash
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong
Activity
asottile-sentry commentedon May 2, 2024
deleting the bigtable
py.typedfile causes it to succeed as well, though I can't really do that (but it might hint at a solution?)asottile-sentry commentedon May 2, 2024
I believe this causes the bug -- or at least commenting it out "fixes" my problem --
mypy/mypy/modulefinder.py
Lines 543 to 549 in fb31409
asottile-sentry commentedon May 2, 2024
appears to be a duplicate of #10360