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: 9 additions & 8 deletions google/cloud/datastore/client.py
Expand Up @@ -17,10 +17,10 @@
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
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 @@ -32,13 +32,14 @@

try:
from google.cloud.datastore._gapic import make_datastore_api

except ImportError: # pragma: NO COVER
from google.api_core import client_info
from google.api_core import client_info as api_core_client_info

def make_datastore_api(client):
raise RuntimeError("No gRPC available")

make_datastore_api = None
_HAVE_GRPC = False
_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)
_CLIENT_INFO = api_core_client_info.ClientInfo(client_library_version=__version__)
else:
from google.api_core.gapic_v1 import client_info

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
10 changes: 10 additions & 0 deletions noxfile.py
Expand Up @@ -37,6 +37,7 @@
nox.options.sessions = [
"unit",
"system",
"mypy",
"cover",
"lint",
"lint_setup_py",
Expand Down Expand Up @@ -72,6 +73,15 @@ def blacken(session):
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def mypy(session):
"""Verify type hints are mypy compatible."""
session.install("-e", ".")
session.install("mypy")
# TODO: also verify types on tests, all of google package
session.run("mypy", "-p", "google.cloud.datastore", "--no-incremental")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
Expand Down
33 changes: 33 additions & 0 deletions owlbot.py
Expand Up @@ -200,4 +200,37 @@ def docfx(session):
""",
)

# add type checker nox session
s.replace("noxfile.py",
"""nox.options.sessions = \[
"unit",
"system",""",
"""nox.options.sessions = [
"unit",
"system",
"mypy",""",
)


s.replace(
"noxfile.py",
"""\
@nox.session\(python=DEFAULT_PYTHON_VERSION\)
def lint_setup_py\(session\):
""",
'''\
@nox.session(python=DEFAULT_PYTHON_VERSION)
def mypy(session):
"""Verify type hints are mypy compatible."""
session.install("-e", ".")
session.install("mypy")
# TODO: also verify types on tests, all of google package
session.run("mypy", "-p", "google.cloud.datastore", "--no-incremental")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint_setup_py(session):
''',
)

s.shell.run(["nox", "-s", "blacken"], hide_output=False)