-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Empty vs filled cache inconsistency for google-cloud-logging & google-cloud-pubsub together with type: ignore
comments
#19037
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
Comments
We definitely have problems when only sub-packages contain $ find .venv/lib/python3.13/site-packages/google -name 'py.typed'
.venv/lib/python3.13/site-packages/google/auth/py.typed
.venv/lib/python3.13/site-packages/google/oauth2/py.typed
.venv/lib/python3.13/site-packages/google/api_core/py.typed
.venv/lib/python3.13/site-packages/google/pubsub_v1/py.typed
.venv/lib/python3.13/site-packages/google/pubsub/py.typed
.venv/lib/python3.13/site-packages/google/cloud/appengine_logging/py.typed
.venv/lib/python3.13/site-packages/google/cloud/appengine_logging_v1/py.typed
.venv/lib/python3.13/site-packages/google/cloud/logging_v2/py.typed
.venv/lib/python3.13/site-packages/google/cloud/logging/py.typed
.venv/lib/python3.13/site-packages/google/cloud/_http/py.typed
.venv/lib/python3.13/site-packages/google/cloud/environment_vars/py.typed
.venv/lib/python3.13/site-packages/google/cloud/obsolete/py.typed
.venv/lib/python3.13/site-packages/google/cloud/_testing/py.typed
.venv/lib/python3.13/site-packages/google/cloud/exceptions/py.typed
.venv/lib/python3.13/site-packages/google/cloud/operation/py.typed
.venv/lib/python3.13/site-packages/google/cloud/client/py.typed
.venv/lib/python3.13/site-packages/google/cloud/_helpers/py.typed |
If anyone wants to jump in, the following can be used to achieve reasonable check times and iterate quickly while still reproducing the same errors (assuming direct installation in venv in cwd instead of rm -rf .venv/lib/python*/site-packages/google/{api,api_core,auth,gapic,iam,longrunning,oauth2,protobuf,pubsub,pubsub_v1,rpc,type,_upb,logging}
rm -rf .venv/lib/python*/site-packages/google/cloud/{appengine_logging,appengine_logging_v1,_helpers,_testing,pubsub,location,obsolete,_http,audit,exceptions,operation,environment_vars,logging_v2/{handlers,services,types},pubsub_v1/{types,publisher,subscriber}} |
Okay, the behaviour of 2nd and subsequent runs seems to be correct. As usual, there are two things that are most difficult to get correctly... And this one is a caching issue. When we look up sources, we may run Lines 579 to 581 in bd1f51a
...except that it doesn't because I have a patch for this, but haven't managed to extract a simple testcase yet. Let's move the following discussion to #19044. |
Bug Report
Running Mypy on a certain set of files (see below) that import things from both the
google-cloud-logging
andgoogle-cloud-pubsub
packages with some# type: ignore
comments applied results in different type checking outcomes (failure vs success) depending on whether the cache has been populated or not.To Reproduce
❗ Note: There is a bash script at the end of this section to make reproducing this more convenient!
bug
with an__init__.py
and these two files:foo.py
:bar.py
:Create a venv with
mypy
,google-cloud-logging
, andgoogle-cloud-pubsub
installed.Ensure there is no
.mypy_cache
dir present.Run
mypy --strict bug/
twice.❗ Script to perform all these steps automatically
Needs
uv
to be installed.Expected Behavior
Both
mypy
invocations result in the same outcome.Actual Behavior
The first invocation reports some errors:
While the second invocation reports success:
Your Environment
master
and it's the same--strict
to get 1 more error that differs between invocations, but the basic issue also appears without itmypy.ini
(and other config files): noneAdditional Context
I'm actually trying to create a minimal reproducible example for a slightly different, more severe issue involving these two packages, in which there is no possible configuration ofNever mind, puttingtype: ignore
comments (or lack thereof) that satisfies Mypy, but this is proving much more difficult to boil down (only seems to happen in our production repo). My hope is that this issue here is "related enough" to it that fixing one will fix both 🤞# type: ignore
on all of the imports but none of the usages did satisfy Mypy. But this issue here still made it needlessly difficult to arrive at that solution by trial and error, and it hints at perhaps more general caching bugs, so it should still be fixed IMHO.Related Issues
google-cloud-logging
weirdness.The text was updated successfully, but these errors were encountered: