No attribute 'Type' on module 'google.cloud.spanner_v1' [module-attr]
With pytype 2022.9.19 and google-cloud-spanner 3.21.0, I'm getting this error:
File "/home/runner/work/python-spanner-orm/python-spanner-orm/spanner_orm/table_apis.py", line 55, in <module>: No attribute 'Type' on module 'google.cloud.spanner_v1' [module-attr]
https://github.com/googleapis/python-spanner/blob/v3.21.0/google/cloud/spanner_v1/init.py imports Type on line 59 and includes it in __all__ on line 135, so I think the attribute should exist.
When I look at the imports information that pytype's computed for table_apis.py, I see:
google/cloud/spanner_v1/transaction /usr/local/google/home/rechen/python-spanner-orm/.pytype/imports/default.pyi
So somehow the from google.cloud import spanner_v1 import is just being ignored.
importlab is generating the right dependency tree, so that's not the issue:
$ importlab spanner_orm/table_apis.py --tree --trim
Reading 1 files
Source tree:
+ spanner_orm/table_apis.py
:: logging/__init__.py
:: typing.py
:: google/cloud/spanner.py
:: google/cloud/spanner_v1/__init__.py
:: google/cloud/spanner_v1/transaction.py
Ohhh the problem is that typeshed has some google/cloud stubs: https://github.com/python/typeshed/tree/master/stubs/google-cloud-ndb. They're supposed to be for the google-cloud-ndb package, but pytype doesn't check whether a package is installed before using typeshed stubs. So it thinks that google/cloud/spanner_v1 can be looked up in typeshed and therefore doesn't need to be in the .imports file.
Ha, seems like I made (and forgot) the same observation in https://github.com/google/pytype/issues/1081. I think I have a fix.
This was fixed by https://github.com/google/pytype/pull/1291, which will be in the next release (sometime next week).