henribru/googleapis-common-protos-stubs

googleapis-common-protos is now using native namespace packages

sevein opened this issue · 5 comments

sevein commented

The README in this project reads:

Note that if you're using Mypy you need to use the --namespace-packages option as google and some of its subpackages are namespace packages.

I wanted to bring up that the warning above may have to be updated somehow given that googleapis-common-protos v1.62.0 has been migrated to native namespace packages. Related issue: googleapis/python-api-common-protos#187.

For me this change caused this error when running mypy after the upgrade:

error: Module "google.rpc" has no attribute "code_pb2"  [attr-defined]

I had to make this change to fix it:

[tool.mypy]
-namespace_packages = true
+namespace_packages = false

Thank you for this project, @henribru!

Thanks for the heads up! I'm having some trouble reproducing this issue, unfortunately. Is it failing at a simple import google.rpc.code_pb2/from google.rpc import code_pb2? Which version of Mypy are you using? Do you have any other Google packages or stubs for them installed? You don't happen to have your own package called google or somthing like that?

One thing I'm noticing is that the PR you linked appears to actually have turned some subpackages that previously were not namespace packages into namespace packges. Namely all the ones with empty removed __init__.pys here: https://github.com/googleapis/python-api-common-protos/pull/187/files I should probably remove the corresponding __init__.pys in my stubs.

google.rpc isn't one of these, but google.rpc.context is. google.rpc also was never declared as a namespace package in setup.py. But not sure if any of that is relevant to the issue you're seeing.

sevein commented

I'll see if I can find a good way to show how to reproduce, will get back to you soon. Thanks!

sevein commented

I've just discovered that the problem started happening when I upgraded types-protobuf from 4.24.0.4 to 4.24.0.20240106. I don't understant what the problem is. This may be related: python/typeshed#11254. Feel free to close this issue, sorry for the noise!

I'm not able to reproduce it with that version of types-protobuf either, but it sounds plausible for that issue to be the cause. I'll close this, but let me know if it's not resolved after python/typeshed#11254 is fixed and I'll investigate further.