pytype icon indicating copy to clipboard operation
pytype copied to clipboard

No attribute 'Type' on module 'google.cloud.spanner_v1' [module-attr]

Open dseomn opened this issue 3 years ago • 4 comments

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.

dseomn avatar Sep 20 '22 21:09 dseomn

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.

rchen152 avatar Sep 22 '22 04:09 rchen152

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

rchen152 avatar Sep 22 '22 04:09 rchen152

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.

rchen152 avatar Sep 22 '22 04:09 rchen152

Ha, seems like I made (and forgot) the same observation in https://github.com/google/pytype/issues/1081. I think I have a fix.

rchen152 avatar Sep 22 '22 06:09 rchen152

This was fixed by https://github.com/google/pytype/pull/1291, which will be in the next release (sometime next week).

rchen152 avatar Sep 23 '22 00:09 rchen152