googleapis/python-datastore

Add a py.typed file for submodule

Closed this issue · 4 comments

To be in accordance with PEP 561 we should add a py.typed file to google/cloud/datastore/py.typed

The file can be empty but does need to be present for some type checkers.

Reopening as to be done, we ought to ensure passage. Do note, you may need to run mypy, pyright, pytype against our samples before merging. It will ensure that we aren't exposing users to failing type checks.

Ideally we would add this to CI as well, to avoid future breakage.

TODO:
currently the code as merged is validating the package, google.cloud.datastore.

We want to evaluate mypy against google and tests

Once https://www.github.com/googleapis/gapic-generator-python/issues/1026 is addressed, we should be unblocked to wrap this up.

I have a WIP locally which passes.

$ .nox/mypy/bin/mypy google/ tests
Success: no issues found in 66 source files

In addition to tweaking noxfile.py to install additional types-* packages, I needed to apply the changes which should be generated by these two gapic-generator-python PRs:

However, there is another issue which is un-addressed by those PRs: the generated code for the datastore_admin_v1 clients declares invalid / unknown types for the labels parameters to import_entities and export_entites:

$ .nox/mypy/bin/mypy google/
google/cloud/datastore_admin_v1/services/datastore_admin/client.py:384: error: Name "datastore_admin.ExportEntitiesRequest.LabelsEntry" is not defined
google/cloud/datastore_admin_v1/services/datastore_admin/client.py:523: error: Name "datastore_admin.ImportEntitiesRequest.LabelsEntry" is not defined
google/cloud/datastore_admin_v1/services/datastore_admin/async_client.py:209: error: Name "datastore_admin.ExportEntitiesRequest.LabelsEntry" is not defined
google/cloud/datastore_admin_v1/services/datastore_admin/async_client.py:347: error: Name "datastore_admin.ImportEntitiesRequest.LabelsEntry" is not defined

By my reading of the protobuf definition, those parameters should be typed as Dict[str, str], and in fact that makes mypy happy.

The LabelsEntry bug is due to googleapis/gapic-generator-python#689.