Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Generated code for Pub/Sub does not pass type checks with mypy #1092

@plamut

Description

@plamut

Running mypy on the Python Pub/Sub client produces several type check errors.

The errors in the manually written code will be handled by googleapis/python-pubsub#536, but even the generated code produces a few errors on its own. The generator should produce code that passes mypy checks (currently only pytype is used).

In the scope of either this or a stand-alone issue, it would also make sense to add a mypy CI check for the generated code (not just the code of the generator itself) to avoid future type-check regressions.

Reproduction

Clone the google-cloud-python repo into a virtual environment, install the Pub/Sub library in editable mode, and then run the commands seen in the "sample output" section.

Versions:

pytype==2021.4.9
google-cloud-pubsub==2.9.0

Sample output:

$ pip install pytype==2021.4.9
$ pip install types-protobuf types-setuptools
$ python -m mypy google/pubsub_v1
google/pubsub_v1/types/__init__.py:82: error: Name "google" is not defined
google/pubsub_v1/types/__init__.py:83: error: Name "google" is not defined
google/pubsub_v1/services/subscriber/client.py:46: error: Skipping analyzing "grpc": found module but no type hints or library stubs
google/pubsub_v1/services/subscriber/client.py:405: error: Incompatible types in assignment (expression has type "partial[SubscriberTransport]", variable has type "Type[SubscriberTransport]")
google/pubsub_v1/services/subscriber/client.py:1175: error: "Callable[[StreamingPullRequest], Union[StreamingPullResponse, Awaitable[StreamingPullResponse]]]" has no attribute "_prefetch_first_result_"
google/pubsub_v1/services/publisher/client.py:46: error: Skipping analyzing "grpc": found module but no type hints or library stubs
google/pubsub_v1/services/publisher/client.py:46: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
google/pubsub_v1/services/publisher/client.py:403: error: Incompatible types in assignment (expression has type "partial[PublisherTransport]", variable has type "Type[PublisherTransport]")
Found 7 errors in 3 files (checked 29 source files)

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions