8000 fix: improve type hints, mypy check (#242) · googleapis/python-datastore@6398bbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 6398bbc

Browse files
crwilcoxgcf-owl-bot[bot]tseaver
authored
fix: improve type hints, mypy check (#242)
* chore: ensure mypy passes * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: flake8 doesn't like lambdas * test: add mypy test scenarioa * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: scope mypy to google.cloud.datastore for now * chore: remove api_core ignores, quiet a mypy error by import rename * fix: drop unneded extra function Also, have shim 'make_datastore_api' raise an exception, as it only gets called if gRPC is disabled, or not installed. Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Tres Seaver <tseaver@palladion.com>
1 parent dbe20e3 commit 6398bbc

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

google/cloud/datastore/_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

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

17-
from google.rpc import status_pb2
17+
from google.rpc import status_pb2 # type: ignore
1818

1919
from google.cloud import _http as connection_module
20-
from google.cloud import exceptions
20+
from google.cloud import exceptions # type: ignore
2121
from google.cloud.datastore_v1.types import datastore as _datastore_pb2
2222

2323

google/cloud/datastore/client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import warnings
1818

1919
import google.api_core.client_options
20-
from google.auth.credentials import AnonymousCredentials
21-
from google.cloud._helpers import _LocalStack
22-
from google.cloud._helpers import _determine_default_project as _base_default_project
23-
from google.cloud.client import ClientWithProject
20+
from google.auth.credentials import AnonymousCredentials # type: ignore
21+
from google.cloud._helpers import _LocalStack # type: ignore
22+
from google.cloud._helpers import _determine_default_project as _base_default_project # type: ignore
23+
from google.cloud.client import ClientWithProject # type: ignore
2424
from google.cloud.datastore.version import __version__
2525
from google.cloud.datastore import helpers
2626
from google.cloud.datastore._http import HTTPDatastoreAPI
@@ -32,13 +32,14 @@
3232

3333
try:
3434
from google.cloud.datastore._gapic import make_datastore_api
35-
3635
except ImportError: # pragma: NO COVER
37-
from google.api_core import client_info
36+
from google.api_core import client_info as api_core_client_info
37+
38+
def make_datastore_api(client):
39+
raise RuntimeError("No gRPC available")
3840

39-
make_datastore_api = None
4041
_HAVE_GRPC = False
41-
_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)
42+
_CLIENT_INFO = api_core_client_info.ClientInfo(client_library_version=__version__)
4243
else:
4344
from google.api_core.gapic_v1 import client_info
4445

mypy.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[mypy]
2+
python_version = 3.6
3+
namespace_packages = True
4+
ignore_missing_imports = True
5+
6+
[mypy-google.protobuf]
7+
ignore_missing_imports = True

noxfile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
nox.options.sessions = [
3838
"unit",
3939
"system",
40+
"mypy",
4041
"cover",
4142
"lint",
4243
"lint_setup_py",
@@ -72,6 +73,15 @@ def blacken(session):
7273
)
7374

7475

76+
@nox.session(python=DEFAULT_PYTHON_VERSION)
77+
def mypy(session):
78+
"""Verify type hints are mypy compatible."""
79+
session.install("-e", ".")
80+
session.install("mypy")
81+
# TODO: also verify types on tests, all of google package
82+
session.run("mypy", "-p", "google.cloud.datastore", "--no-incremental")
83+
84+
7585
@nox.session(python=DEFAULT_PYTHON_VERSION)
7686
def lint_setup_py(session):
7787
"""Verify that setup.py is valid (including RST check)."""

owlbot.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,37 @@ def docfx(session):
200200
""",
201201
)
202202

203+
# add type checker nox session
204+
s.replace("noxfile.py",
205+
"""nox.options.sessions = \[
206+
"unit",
207+
"system",""",
208+
"""nox.options.sessions = [
209+
"unit",
210+
"system",
211+
"mypy",""",
212+
)
213+
214+
215+
s.replace(
216+
"noxfile.py",
217+
"""\
218+
@nox.session\(python=DEFAULT_PYTHON_VERSION\)
219+
def lint_setup_py\(session\):
220+
""",
221+
'''\
222+
@nox.session(python=DEFAULT_PYTHON_VERSION)
223+
def mypy(session):
224+
"""Verify type hints are mypy compatible."""
225+
session.install("-e", ".")
226+
session.install("mypy")
227+
# TODO: also verify types on tests, all of google package
228+
session.run("mypy", "-p", "google.cloud.datastore", "--no-incremental")
229+
230+
231+
@nox.session(python=DEFAULT_PYTHON_VERSION)
232+
def lint_setup_py(session):
233+
''',
234+
)
235+
203236
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

0 commit comments

Comments
 (0)
0