Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ensure mypy passes for package #242

Merged
merged 9 commits into from Oct 14, 2021
4 changes: 2 additions & 2 deletions google/cloud/datastore/_http.py
Expand Up @@ -14,10 +14,10 @@

"""Connections to Google Cloud Datastore API servers."""

from google.rpc import status_pb2
from google.rpc import status_pb2 # type: ignore

from google.cloud import _http as connection_module
from google.cloud import exceptions
from google.cloud import exceptions # type: ignore
from google.cloud.datastore_v1.types import datastore as _datastore_pb2


Expand Down
17 changes: 10 additions & 7 deletions google/cloud/datastore/client.py
Expand Up @@ -16,11 +16,11 @@
import os
import warnings

import google.api_core.client_options
from google.auth.credentials import AnonymousCredentials
from google.cloud._helpers import _LocalStack
from google.cloud._helpers import _determine_default_project as _base_default_project
from google.cloud.client import ClientWithProject
import google.api_core.client_options # type: ignore
from google.auth.credentials import AnonymousCredentials # type: ignore
from google.cloud._helpers import _LocalStack # type: ignore
from google.cloud._helpers import _determine_default_project as _base_default_project # type: ignore
from google.cloud.client import ClientWithProject # type: ignore
from google.cloud.datastore.version import __version__
from google.cloud.datastore import helpers
from google.cloud.datastore._http import HTTPDatastoreAPI
Expand All @@ -36,11 +36,14 @@
except ImportError: # pragma: NO COVER
from google.api_core import client_info

make_datastore_api = None
def no_datastore_api(self):
return None

make_datastore_api = no_datastore_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this just a function?

Suggested change
def no_datastore_api(self):
return None
make_datastore_api = no_datastore_api
def make_datastore_api(self):
return None

And maybe it should raise an exception, since the only reason we're here is that gRPC is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be a lambda but flake8 isn't a fan and I am not going to protest loudly about it. This is a minimal change that ensures make_datastore_api is consistently a callable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't see the point in defining the no_datastore_api function, only to alias it as make_datastore_api -- just name the function make_datastore_api.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it, but if you do that you end up fighting with google/cloud/datastore/client.py:41: error: All conditional function variants must have identical signatures :\ This seems not terrible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed d6b600a, which passes mypy, and removes the extra no_database_api function.

_HAVE_GRPC = False
_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)
else:
from google.api_core.gapic_v1 import client_info
from google.api_core.gapic_v1 import client_info # type: ignore

_HAVE_GRPC = True
_CLIENT_INFO = client_info.ClientInfo(
Expand Down
7 changes: 7 additions & 0 deletions mypy.ini
@@ -0,0 +1,7 @@
[mypy]
python_version = 3.6
namespace_packages = True
ignore_missing_imports = True

[mypy-google.protobuf]
ignore_missing_imports = True