8000 ci: expand mypy coverage (#476) · googleapis/google-cloud-python@51bde1e · GitHub
[go: up one dir, main page]

Skip to content

Commit 51bde1e

Browse files
authored
ci: expand mypy coverage (#476)
* Work around invalid generated typing for map fields See: googleapis/gapic-generator-python#689 * Restore missing namespace marker file * Get mypy running against all modules in 'google/' / 'tests/' Note we still exclude generated tests, due to broken typing emitted from the gapic-generator.
1 parent 0537dd2 commit 51bde1e

File tree

7 files changed

+81
-13
lines changed

7 files changed

+81
-13
lines changed

packages/google-cloud-bigtable/.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
branch = True
2020
omit =
2121
google/cloud/__init__.py
22+
google/__init__.py
2223

2324
[report]
2425
fail_under = 100
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
try:
4+
import pkg_resources
5+
6+
pkg_resources.declare_namespace(__name__)
7+
except ImportError:
8+
import pkgutil
9+
10+
__path__: List[str] = pkgutil.extend_path(__path__, __name__)

packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ async def create_instance(
199199
parent: str = None,
200200
instance_id: str = None,
201201
instance: gba_instance.Instance = None,
202-
clusters: Sequence[
203-
bigtable_instance_admin.CreateInstanceRequest.ClustersEntry
204-
] = None,
202+
clusters: Dict[str, gba_instance.Cluster] = None,
205203
retry: OptionalRetry = gapic_v1.method.DEFAULT,
206204
timeout: float = None,
207205
metadata: Sequence[Tuple[str, str]] = (),
@@ -235,7 +233,7 @@ async def create_instance(
235233
This corresponds to the ``instance`` field
236234
on the ``request`` instance; if ``request`` is provided, this
237235
should not be set.
238-
clusters (:class:`Sequence[google.cloud.bigtable_admin_v2.types.CreateInstanceRequest.ClustersEntry]`):
236+
clusters (Dict[str, gba_instance.Cluster]):
239237
Required. The clusters to be created within the
240238
instance, mapped by desired cluster ID, e.g., just
241239
``mycluster`` rather than

packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,7 @@ def create_instance(
430430
parent: str = None,
431431
instance_id: str = None,
432432
instance: gba_instance.Instance = None,
433-
clusters: Sequence[
434-
bigtable_instance_admin.CreateInstanceRequest.ClustersEntry
435-
] = None,
433+
clusters: Dict[str, gba_instance.Cluster] = None,
436434
retry: OptionalRetry = gapic_v1.method.DEFAULT,
437435
timeout: float = None,
438436
metadata: Sequence[Tuple[str, str]] = (),
@@ -466,7 +464,7 @@ def create_instance(
466464
This corresponds to the ``instance`` field
467465
on the ``request`` instance; if ``request`` is provided, this
468466
should not be set.
469-
clusters (Sequence[google.cloud.bigtable_admin_v2.types.CreateInstanceRequest.ClustersEntry]):
467+
clusters (Dict[str, gba_instance.Cluster]):
470468
Required. The clusters to be created within the
471469
instance, mapped by desired cluster ID, e.g., just
472470
``mycluster`` rather than
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
[mypy]
22
python_version = 3.6
33
namespace_packages = True
4+
exclude = tests/unit/gapic/
45

5-
[mypy-google.protobuf]
6+
[mypy-grpc.*]
7+
ignore_missing_imports = True
8+
9+
[mypy-google.auth.*]
10+
ignore_missing_imports = True
11+
12+
[mypy-google.iam.*]
13+
ignore_missing_imports = True
14+
15+
[mypy-google.longrunning.*]
16+
ignore_missing_imports = True
17+
18+
[mypy-google.oauth2.*]
19+
ignore_missing_imports = True
20+
21+
[mypy-google.rpc.*]
22+
ignore_missing_imports = True
23+
24+
[mypy-proto.*]
25+
ignore_missing_imports = True
26+
27+
[mypy-pytest]
628
ignore_missing_imports = True

packages/google-cloud-bigtable/noxfile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ def blacken(session):
7777
def mypy(session):
7878
"""Verify type hints are mypy compatible."""
7979
session.install("-e", ".")
80-
session.install("mypy", "types-setuptools")
80+
session.install("mypy", "types-setuptools", "types-protobuf", "types-mock")
81+
session.install("google-cloud-testutils")
8182
# TODO: also verify types on tests, all of google package
82-
session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental")
83+
session.run("mypy", "google/", "tests/")
8384

8485

8586
@nox.session(python=DEFAULT_PYTHON_VERSION)

packages/google-cloud-bigtable/owlbot.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""This script is used to synthesize generated parts of this library."""
1616

1717
from pathlib import Path
18+
import re
1819
from typing import List, Optional
1920

2021
import synthtool as s
@@ -165,16 +166,53 @@ def lint_setup_py\(session\):
165166
def mypy(session):
166167
"""Verify type hints are mypy compatible."""
167168
session.install("-e", ".")
168-
session.install("mypy", "types-setuptools")
169+
session.install("mypy", "types-setuptools", "types-protobuf", "types-mock")
170+
session.install("google-cloud-testutils")
169171
# TODO: also verify types on tests, all of google package
170-
session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental")
172+
session.run("mypy", "google/", "tests/")
171173
172174
173175
@nox.session(python=DEFAULT_PYTHON_VERSION)
174176
def lint_setup_py(session):
175177
''',
176178
)
177179

180+
# Work around https://github.com/googleapis/gapic-generator-python/issues/689
181+
bad_clusters_typing = r"""
182+
clusters: Sequence\[
183+
bigtable_instance_admin\.CreateInstanceRequest\.ClustersEntry
184+
\] = None,"""
185+
186+
good_clusters_typing = """
187+
clusters: Dict[str, gba_instance.Cluster] = None,"""
188+
189+
s.replace(
190+
"google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/*client.py",
191+
bad_clusters_typing,
192+
good_clusters_typing,
193+
)
194+
195+
bad_clusters_docstring_1 = re.escape(r"""
196+
clusters (:class:`Sequence[google.cloud.bigtable_admin_v2.types.CreateInstanceRequest.ClustersEntry]`):""")
197+
198+
bad_clusters_docstring_2 = re.escape(r"""
199+
clusters (Sequence[google.cloud.bigtable_admin_v2.types.CreateInstanceRequest.ClustersEntry]):""")
200+
201+
good_clusters_docstring = """
202+
clusters (Dict[str, gba_instance.Cluster]):"""
203+
204+
s.replace(
205+
"google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/*client.py",
206+
bad_clusters_docstring_1,
207+
good_clusters_docstring,
208+
)
209+
210+
s.replace(
211+
"google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/*client.py",
212+
bad_clusters_docstring_2,
213+
good_clusters_docstring,
214+
)
215+
178216
# ----------------------------------------------------------------------------
179217
# Samples templates
180218
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)
0