From 53d679f2464bbb5b760dda5fbdd46163bb36a8ff Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 11:11:36 -0700 Subject: [PATCH 01/20] chore: ensure mypy passes --- google/cloud/__init__.py | 2 +- google/cloud/bigtable/__init__.py | 2 +- google/cloud/bigtable/app_profile.py | 2 +- google/cloud/bigtable/client.py | 17 +++++++++++------ google/cloud/bigtable/instance.py | 2 +- google/cloud/bigtable/policy.py | 2 +- google/cloud/bigtable/row_data.py | 2 +- mypy.ini | 16 ++++++++++++++++ 8 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 mypy.ini diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py index 2f4b4738a..50ad4b74b 100644 --- a/google/cloud/__init__.py +++ b/google/cloud/__init__.py @@ -1,5 +1,5 @@ try: - import pkg_resources + import pkg_resources # type: ignore pkg_resources.declare_namespace(__name__) except ImportError: diff --git a/google/cloud/bigtable/__init__.py b/google/cloud/bigtable/__init__.py index f2c5a24bd..b73f66ef4 100644 --- a/google/cloud/bigtable/__init__.py +++ b/google/cloud/bigtable/__init__.py @@ -15,7 +15,7 @@ """Google Cloud Bigtable API package.""" -import pkg_resources +import pkg_resources # type: ignore try: __version__ = pkg_resources.get_distribution("google-cloud-bigtable").version diff --git a/google/cloud/bigtable/app_profile.py b/google/cloud/bigtable/app_profile.py index 5d6dbdb81..9cc9a109d 100644 --- a/google/cloud/bigtable/app_profile.py +++ b/google/cloud/bigtable/app_profile.py @@ -20,7 +20,7 @@ from google.cloud.bigtable.enums import RoutingPolicyType from google.cloud.bigtable_admin_v2.types import instance from google.protobuf import field_mask_pb2 -from google.api_core.exceptions import NotFound +from google.api_core.exceptions import NotFound # type: ignore _APP_PROFILE_NAME_RE = re.compile( r"^projects/(?P[^/]+)/" diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index 7746ee2ae..40c57bb48 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -29,11 +29,15 @@ """ import os import warnings -import grpc +import grpc # type: ignore +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + __version__ : str from google.api_core.gapic_v1 import client_info -import google.auth -from google.auth.credentials import AnonymousCredentials +import google.auth # type: ignore +from google.auth.credentials import AnonymousCredentials # type: ignore from google.cloud import bigtable_v2 from google.cloud import bigtable_admin_v2 @@ -45,15 +49,16 @@ BigtableTableAdminGrpcTransport, ) -from google.cloud.bigtable import __version__ +from google.cloud.bigtable import __version__ # type: ignore from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.cluster import Cluster -from google.cloud.client import ClientWithProject +from google.cloud.client import ClientWithProject # type: ignore from google.cloud.bigtable_admin_v2.types import instance from google.cloud.bigtable.cluster import _CLUSTER_NAME_RE -from google.cloud.environment_vars import BIGTABLE_EMULATOR +from google.cloud.environment_vars import BIGTABLE_EMULATOR # type: ignore + INSTANCE_TYPE_PRODUCTION = instance.Instance.Type.PRODUCTION diff --git a/google/cloud/bigtable/instance.py b/google/cloud/bigtable/instance.py index e6e2ac027..c9c1c1ac0 100644 --- a/google/cloud/bigtable/instance.py +++ b/google/cloud/bigtable/instance.py @@ -24,7 +24,7 @@ from google.cloud.bigtable_admin_v2.types import instance -from google.iam.v1 import options_pb2 +from google.iam.v1 import options_pb2 # type: ignore from google.api_core.exceptions import NotFound diff --git a/google/cloud/bigtable/policy.py b/google/cloud/bigtable/policy.py index f5558b6f0..1781bd2b4 100644 --- a/google/cloud/bigtable/policy.py +++ b/google/cloud/bigtable/policy.py @@ -16,7 +16,7 @@ from google.api_core.iam import Policy as BasePolicy from google.cloud._helpers import _to_bytes -from google.iam.v1 import policy_pb2 +from google.iam.v1 import policy_pb2 # type: ignore """IAM roles supported by Bigtable Instance resource""" BIGTABLE_ADMIN_ROLE = "roles/bigtable.admin" diff --git a/google/cloud/bigtable/row_data.py b/google/cloud/bigtable/row_data.py index 18d82153b..47ff84a14 100644 --- a/google/cloud/bigtable/row_data.py +++ b/google/cloud/bigtable/row_data.py @@ -17,7 +17,7 @@ import copy -import grpc +import grpc # type: ignore from google.api_core import exceptions from google.api_core import retry diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000..754bf0708 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,16 @@ +[mypy] +python_version = 3.6 +namespace_packages = True + +[mypy-google.protobuf] +ignore_missing_imports = True + + +[mypy-google.api_core.*] +ignore_missing_imports = True + +[mypy-google.cloud._helpers] +ignore_missing_imports = True + +[mypy-google.cloud.exceptions] +ignore_missing_imports = True From c2e2b6daa5f5f2c4978e3cea58149625b7531232 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 13 Oct 2021 18:14:52 +0000 Subject: [PATCH 02/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- google/cloud/__init__.py | 2 +- google/cloud/bigtable/__init__.py | 2 +- google/cloud/bigtable/app_profile.py | 2 +- google/cloud/bigtable/client.py | 13 ++++++------- google/cloud/bigtable/instance.py | 2 +- google/cloud/bigtable/policy.py | 2 +- google/cloud/bigtable/row_data.py | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py index 50ad4b74b..5e80aa293 100644 --- a/google/cloud/__init__.py +++ b/google/cloud/__init__.py @@ -1,5 +1,5 @@ try: - import pkg_resources # type: ignore + import pkg_resources # type: ignore pkg_resources.declare_namespace(__name__) except ImportError: diff --git a/google/cloud/bigtable/__init__.py b/google/cloud/bigtable/__init__.py index b73f66ef4..bb48d5d98 100644 --- a/google/cloud/bigtable/__init__.py +++ b/google/cloud/bigtable/__init__.py @@ -15,7 +15,7 @@ """Google Cloud Bigtable API package.""" -import pkg_resources # type: ignore +import pkg_resources # type: ignore try: __version__ = pkg_resources.get_distribution("google-cloud-bigtable").version diff --git a/google/cloud/bigtable/app_profile.py b/google/cloud/bigtable/app_profile.py index 9cc9a109d..665a578fb 100644 --- a/google/cloud/bigtable/app_profile.py +++ b/google/cloud/bigtable/app_profile.py @@ -20,7 +20,7 @@ from google.cloud.bigtable.enums import RoutingPolicyType from google.cloud.bigtable_admin_v2.types import instance from google.protobuf import field_mask_pb2 -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound # type: ignore _APP_PROFILE_NAME_RE = re.compile( r"^projects/(?P[^/]+)/" diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index 40c57bb48..08a2ddd91 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -29,15 +29,15 @@ """ import os import warnings -import grpc # type: ignore +import grpc # type: ignore from typing import TYPE_CHECKING if TYPE_CHECKING: - __version__ : str + __version__: str from google.api_core.gapic_v1 import client_info -import google.auth # type: ignore -from google.auth.credentials import AnonymousCredentials # type: ignore +import google.auth # type: ignore +from google.auth.credentials import AnonymousCredentials # type: ignore from google.cloud import bigtable_v2 from google.cloud import bigtable_admin_v2 @@ -53,12 +53,11 @@ from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.cluster import Cluster -from google.cloud.client import ClientWithProject # type: ignore +from google.cloud.client import ClientWithProject # type: ignore from google.cloud.bigtable_admin_v2.types import instance from google.cloud.bigtable.cluster import _CLUSTER_NAME_RE -from google.cloud.environment_vars import BIGTABLE_EMULATOR # type: ignore - +from google.cloud.environment_vars import BIGTABLE_EMULATOR # type: ignore INSTANCE_TYPE_PRODUCTION = instance.Instance.Type.PRODUCTION diff --git a/google/cloud/bigtable/instance.py b/google/cloud/bigtable/instance.py index c9c1c1ac0..9c22aaa79 100644 --- a/google/cloud/bigtable/instance.py +++ b/google/cloud/bigtable/instance.py @@ -24,7 +24,7 @@ from google.cloud.bigtable_admin_v2.types import instance -from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore from google.api_core.exceptions import NotFound diff --git a/google/cloud/bigtable/policy.py b/google/cloud/bigtable/policy.py index 1781bd2b4..5f10c092b 100644 --- a/google/cloud/bigtable/policy.py +++ b/google/cloud/bigtable/policy.py @@ -16,7 +16,7 @@ from google.api_core.iam import Policy as BasePolicy from google.cloud._helpers import _to_bytes -from google.iam.v1 import policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore """IAM roles supported by Bigtable Instance resource""" BIGTABLE_ADMIN_ROLE = "roles/bigtable.admin" diff --git a/google/cloud/bigtable/row_data.py b/google/cloud/bigtable/row_data.py index 47ff84a14..ca3428244 100644 --- a/google/cloud/bigtable/row_data.py +++ b/google/cloud/bigtable/row_data.py @@ -17,7 +17,7 @@ import copy -import grpc # type: ignore +import grpc # type: ignore from google.api_core import exceptions from google.api_core import retry From 65c902467c17fd20e5db97a2f2be108050c8c674 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 11:18:18 -0700 Subject: [PATCH 03/20] chore: move type info to inline, not mypy.ini --- google/cloud/__init__.py | 2 +- google/cloud/bigtable/backup.py | 4 ++-- google/cloud/bigtable/client.py | 2 +- google/cloud/bigtable/cluster.py | 2 +- google/cloud/bigtable/instance.py | 2 +- google/cloud/bigtable/policy.py | 4 ++-- google/cloud/bigtable/row.py | 6 +++--- google/cloud/bigtable/row_data.py | 8 ++++---- google/cloud/bigtable/row_filters.py | 4 ++-- google/cloud/bigtable/row_set.py | 2 +- google/cloud/bigtable/table.py | 10 +++++----- mypy.ini | 10 ---------- 12 files changed, 23 insertions(+), 33 deletions(-) diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py index 50ad4b74b..2f4b4738a 100644 --- a/google/cloud/__init__.py +++ b/google/cloud/__init__.py @@ -1,5 +1,5 @@ try: - import pkg_resources # type: ignore + import pkg_resources pkg_resources.declare_namespace(__name__) except ImportError: diff --git a/google/cloud/bigtable/backup.py b/google/cloud/bigtable/backup.py index 0991e85f5..14736e013 100644 --- a/google/cloud/bigtable/backup.py +++ b/google/cloud/bigtable/backup.py @@ -16,12 +16,12 @@ import re -from google.cloud._helpers import _datetime_to_pb_timestamp +from google.cloud._helpers import _datetime_to_pb_timestamp # type: ignore from google.cloud.bigtable_admin_v2 import BigtableTableAdminClient from google.cloud.bigtable_admin_v2.types import table from google.cloud.bigtable.encryption_info import EncryptionInfo from google.cloud.bigtable.policy import Policy -from google.cloud.exceptions import NotFound +from google.cloud.exceptions import NotFound # type: ignore from google.protobuf import field_mask_pb2 _BACKUP_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index 40c57bb48..c601f7060 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -35,7 +35,7 @@ if TYPE_CHECKING: __version__ : str -from google.api_core.gapic_v1 import client_info +from google.api_core.gapic_v1 import client_info # type: ignore import google.auth # type: ignore from google.auth.credentials import AnonymousCredentials # type: ignore diff --git a/google/cloud/bigtable/cluster.py b/google/cloud/bigtable/cluster.py index f3e79c6c2..9794796cd 100644 --- a/google/cloud/bigtable/cluster.py +++ b/google/cloud/bigtable/cluster.py @@ -17,7 +17,7 @@ import re from google.cloud.bigtable_admin_v2.types import instance -from google.api_core.exceptions import NotFound +from google.api_core.exceptions import NotFound # type: ignore _CLUSTER_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/instance.py b/google/cloud/bigtable/instance.py index c9c1c1ac0..01e8cc729 100644 --- a/google/cloud/bigtable/instance.py +++ b/google/cloud/bigtable/instance.py @@ -26,7 +26,7 @@ from google.iam.v1 import options_pb2 # type: ignore -from google.api_core.exceptions import NotFound +from google.api_core.exceptions import NotFound # type: ignore from google.cloud.bigtable.policy import Policy diff --git a/google/cloud/bigtable/policy.py b/google/cloud/bigtable/policy.py index 1781bd2b4..000533169 100644 --- a/google/cloud/bigtable/policy.py +++ b/google/cloud/bigtable/policy.py @@ -14,8 +14,8 @@ import base64 -from google.api_core.iam import Policy as BasePolicy -from google.cloud._helpers import _to_bytes +from google.api_core.iam import Policy as BasePolicy # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.iam.v1 import policy_pb2 # type: ignore """IAM roles supported by Bigtable Instance resource""" diff --git a/google/cloud/bigtable/row.py b/google/cloud/bigtable/row.py index 3fdc230f7..4b745183c 100644 --- a/google/cloud/bigtable/row.py +++ b/google/cloud/bigtable/row.py @@ -17,9 +17,9 @@ import struct -from google.cloud._helpers import _datetime_from_microseconds -from google.cloud._helpers import _microseconds_from_datetime -from google.cloud._helpers import _to_bytes +from google.cloud._helpers import _datetime_from_microseconds # type: ignore +from google.cloud._helpers import _microseconds_from_datetime # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import data as data_v2_pb2 diff --git a/google/cloud/bigtable/row_data.py b/google/cloud/bigtable/row_data.py index 47ff84a14..bf3f7618e 100644 --- a/google/cloud/bigtable/row_data.py +++ b/google/cloud/bigtable/row_data.py @@ -19,10 +19,10 @@ import grpc # type: ignore -from google.api_core import exceptions -from google.api_core import retry -from google.cloud._helpers import _datetime_from_microseconds -from google.cloud._helpers import _to_bytes +from google.api_core import exceptions # type: ignore +from google.api_core import retry # type: ignore +from google.cloud._helpers import _datetime_from_microseconds # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import bigtable as data_messages_v2_pb2 from google.cloud.bigtable_v2.types import data as data_v2_pb2 diff --git a/google/cloud/bigtable/row_filters.py b/google/cloud/bigtable/row_filters.py index b495fb646..19af1b5e1 100644 --- a/google/cloud/bigtable/row_filters.py +++ b/google/cloud/bigtable/row_filters.py @@ -17,8 +17,8 @@ import struct -from google.cloud._helpers import _microseconds_from_datetime -from google.cloud._helpers import _to_bytes +from google.cloud._helpers import _microseconds_from_datetime # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import data as data_v2_pb2 _PACK_I64 = struct.Struct(">q").pack diff --git a/google/cloud/bigtable/row_set.py b/google/cloud/bigtable/row_set.py index 32a9bd1e3..f86faa02a 100644 --- a/google/cloud/bigtable/row_set.py +++ b/google/cloud/bigtable/row_set.py @@ -15,7 +15,7 @@ """User-friendly container for Google Cloud Bigtable RowSet """ -from google.cloud._helpers import _to_bytes +from google.cloud._helpers import _to_bytes # type: ignore class RowSet(object): diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index 8dc4f5e42..6cf08ad38 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -16,16 +16,16 @@ import warnings -from google.api_core import timeout -from google.api_core.exceptions import Aborted +from google.api_core import timeout # type: ignore +from google.api_core.exceptions import Aborted # type: ignore from google.api_core.exceptions import DeadlineExceeded from google.api_core.exceptions import NotFound from google.api_core.exceptions import RetryError from google.api_core.exceptions import ServiceUnavailable -from google.api_core.gapic_v1.method import DEFAULT -from google.api_core.retry import if_exception_type +from google.api_core.gapic_v1.method import DEFAULT # type: ignore +from google.api_core.retry import if_exception_type # type: ignore from google.api_core.retry import Retry -from google.cloud._helpers import _to_bytes +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable.backup import Backup from google.cloud.bigtable.column_family import _gc_rule_from_pb from google.cloud.bigtable.column_family import ColumnFamily diff --git a/mypy.ini b/mypy.ini index 754bf0708..9aef441de 100644 --- a/mypy.ini +++ b/mypy.ini @@ -4,13 +4,3 @@ namespace_packages = True [mypy-google.protobuf] ignore_missing_imports = True - - -[mypy-google.api_core.*] -ignore_missing_imports = True - -[mypy-google.cloud._helpers] -ignore_missing_imports = True - -[mypy-google.cloud.exceptions] -ignore_missing_imports = True From b8e02fd996a574a4d3224d944d02a72aa5a79b27 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 13 Oct 2021 18:21:45 +0000 Subject: [PATCH 04/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- google/cloud/bigtable/backup.py | 4 ++-- google/cloud/bigtable/cluster.py | 2 +- google/cloud/bigtable/instance.py | 2 +- google/cloud/bigtable/row.py | 6 +++--- google/cloud/bigtable/row_data.py | 8 ++++---- google/cloud/bigtable/row_filters.py | 4 ++-- google/cloud/bigtable/row_set.py | 2 +- google/cloud/bigtable/table.py | 10 +++++----- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/google/cloud/bigtable/backup.py b/google/cloud/bigtable/backup.py index 14736e013..c2b5ec9ee 100644 --- a/google/cloud/bigtable/backup.py +++ b/google/cloud/bigtable/backup.py @@ -16,12 +16,12 @@ import re -from google.cloud._helpers import _datetime_to_pb_timestamp # type: ignore +from google.cloud._helpers import _datetime_to_pb_timestamp # type: ignore from google.cloud.bigtable_admin_v2 import BigtableTableAdminClient from google.cloud.bigtable_admin_v2.types import table from google.cloud.bigtable.encryption_info import EncryptionInfo from google.cloud.bigtable.policy import Policy -from google.cloud.exceptions import NotFound # type: ignore +from google.cloud.exceptions import NotFound # type: ignore from google.protobuf import field_mask_pb2 _BACKUP_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/cluster.py b/google/cloud/bigtable/cluster.py index 9794796cd..82fcc24d8 100644 --- a/google/cloud/bigtable/cluster.py +++ b/google/cloud/bigtable/cluster.py @@ -17,7 +17,7 @@ import re from google.cloud.bigtable_admin_v2.types import instance -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound # type: ignore _CLUSTER_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/instance.py b/google/cloud/bigtable/instance.py index c46134682..9bd78d00b 100644 --- a/google/cloud/bigtable/instance.py +++ b/google/cloud/bigtable/instance.py @@ -26,7 +26,7 @@ from google.iam.v1 import options_pb2 # type: ignore -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound # type: ignore from google.cloud.bigtable.policy import Policy diff --git a/google/cloud/bigtable/row.py b/google/cloud/bigtable/row.py index 4b745183c..9127a1aae 100644 --- a/google/cloud/bigtable/row.py +++ b/google/cloud/bigtable/row.py @@ -17,9 +17,9 @@ import struct -from google.cloud._helpers import _datetime_from_microseconds # type: ignore -from google.cloud._helpers import _microseconds_from_datetime # type: ignore -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _datetime_from_microseconds # type: ignore +from google.cloud._helpers import _microseconds_from_datetime # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import data as data_v2_pb2 diff --git a/google/cloud/bigtable/row_data.py b/google/cloud/bigtable/row_data.py index c98c86ba2..59b60a58b 100644 --- a/google/cloud/bigtable/row_data.py +++ b/google/cloud/bigtable/row_data.py @@ -19,10 +19,10 @@ import grpc # type: ignore -from google.api_core import exceptions # type: ignore -from google.api_core import retry # type: ignore -from google.cloud._helpers import _datetime_from_microseconds # type: ignore -from google.cloud._helpers import _to_bytes # type: ignore +from google.api_core import exceptions # type: ignore +from google.api_core import retry # type: ignore +from google.cloud._helpers import _datetime_from_microseconds # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import bigtable as data_messages_v2_pb2 from google.cloud.bigtable_v2.types import data as data_v2_pb2 diff --git a/google/cloud/bigtable/row_filters.py b/google/cloud/bigtable/row_filters.py index 19af1b5e1..53192acc8 100644 --- a/google/cloud/bigtable/row_filters.py +++ b/google/cloud/bigtable/row_filters.py @@ -17,8 +17,8 @@ import struct -from google.cloud._helpers import _microseconds_from_datetime # type: ignore -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _microseconds_from_datetime # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import data as data_v2_pb2 _PACK_I64 = struct.Struct(">q").pack diff --git a/google/cloud/bigtable/row_set.py b/google/cloud/bigtable/row_set.py index f86faa02a..82a540b5a 100644 --- a/google/cloud/bigtable/row_set.py +++ b/google/cloud/bigtable/row_set.py @@ -15,7 +15,7 @@ """User-friendly container for Google Cloud Bigtable RowSet """ -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore class RowSet(object): diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index 6cf08ad38..30befe5c4 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -16,16 +16,16 @@ import warnings -from google.api_core import timeout # type: ignore -from google.api_core.exceptions import Aborted # type: ignore +from google.api_core import timeout # type: ignore +from google.api_core.exceptions import Aborted # type: ignore from google.api_core.exceptions import DeadlineExceeded from google.api_core.exceptions import NotFound from google.api_core.exceptions import RetryError from google.api_core.exceptions import ServiceUnavailable -from google.api_core.gapic_v1.method import DEFAULT # type: ignore -from google.api_core.retry import if_exception_type # type: ignore +from google.api_core.gapic_v1.method import DEFAULT # type: ignore +from google.api_core.retry import if_exception_type # type: ignore from google.api_core.retry import Retry -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable.backup import Backup from google.cloud.bigtable.column_family import _gc_rule_from_pb from google.cloud.bigtable.column_family import ColumnFamily From 2fbaaff1ad24009be21a6aff550d255988d5d6e4 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 13:46:00 -0700 Subject: [PATCH 05/20] test: add mypy test scenario --- google/cloud/bigtable/backup.py | 4 ++-- google/cloud/bigtable/client.py | 2 +- google/cloud/bigtable/cluster.py | 2 +- google/cloud/bigtable/instance.py | 2 +- google/cloud/bigtable/policy.py | 4 ++-- google/cloud/bigtable/row.py | 6 ++--- google/cloud/bigtable/row_data.py | 8 +++---- google/cloud/bigtable/row_filters.py | 4 ++-- google/cloud/bigtable/row_set.py | 2 +- google/cloud/bigtable/table.py | 10 ++++----- noxfile.py | 10 +++++++++ owlbot.py | 33 +++++++++++++++++++++++++++- 12 files changed, 64 insertions(+), 23 deletions(-) diff --git a/google/cloud/bigtable/backup.py b/google/cloud/bigtable/backup.py index 14736e013..c2b5ec9ee 100644 --- a/google/cloud/bigtable/backup.py +++ b/google/cloud/bigtable/backup.py @@ -16,12 +16,12 @@ import re -from google.cloud._helpers import _datetime_to_pb_timestamp # type: ignore +from google.cloud._helpers import _datetime_to_pb_timestamp # type: ignore from google.cloud.bigtable_admin_v2 import BigtableTableAdminClient from google.cloud.bigtable_admin_v2.types import table from google.cloud.bigtable.encryption_info import EncryptionInfo from google.cloud.bigtable.policy import Policy -from google.cloud.exceptions import NotFound # type: ignore +from google.cloud.exceptions import NotFound # type: ignore from google.protobuf import field_mask_pb2 _BACKUP_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index 08a2ddd91..d9b6441e7 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -35,7 +35,7 @@ if TYPE_CHECKING: __version__: str -from google.api_core.gapic_v1 import client_info +from google.api_core.gapic_v1 import client_info # type: ignore import google.auth # type: ignore from google.auth.credentials import AnonymousCredentials # type: ignore diff --git a/google/cloud/bigtable/cluster.py b/google/cloud/bigtable/cluster.py index 9794796cd..82fcc24d8 100644 --- a/google/cloud/bigtable/cluster.py +++ b/google/cloud/bigtable/cluster.py @@ -17,7 +17,7 @@ import re from google.cloud.bigtable_admin_v2.types import instance -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound # type: ignore _CLUSTER_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/instance.py b/google/cloud/bigtable/instance.py index c46134682..9bd78d00b 100644 --- a/google/cloud/bigtable/instance.py +++ b/google/cloud/bigtable/instance.py @@ -26,7 +26,7 @@ from google.iam.v1 import options_pb2 # type: ignore -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound # type: ignore from google.cloud.bigtable.policy import Policy diff --git a/google/cloud/bigtable/policy.py b/google/cloud/bigtable/policy.py index 5f10c092b..7ce917a19 100644 --- a/google/cloud/bigtable/policy.py +++ b/google/cloud/bigtable/policy.py @@ -14,8 +14,8 @@ import base64 -from google.api_core.iam import Policy as BasePolicy -from google.cloud._helpers import _to_bytes +from google.api_core.iam import Policy as BasePolicy # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.iam.v1 import policy_pb2 # type: ignore """IAM roles supported by Bigtable Instance resource""" diff --git a/google/cloud/bigtable/row.py b/google/cloud/bigtable/row.py index 4b745183c..9127a1aae 100644 --- a/google/cloud/bigtable/row.py +++ b/google/cloud/bigtable/row.py @@ -17,9 +17,9 @@ import struct -from google.cloud._helpers import _datetime_from_microseconds # type: ignore -from google.cloud._helpers import _microseconds_from_datetime # type: ignore -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _datetime_from_microseconds # type: ignore +from google.cloud._helpers import _microseconds_from_datetime # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import data as data_v2_pb2 diff --git a/google/cloud/bigtable/row_data.py b/google/cloud/bigtable/row_data.py index c98c86ba2..59b60a58b 100644 --- a/google/cloud/bigtable/row_data.py +++ b/google/cloud/bigtable/row_data.py @@ -19,10 +19,10 @@ import grpc # type: ignore -from google.api_core import exceptions # type: ignore -from google.api_core import retry # type: ignore -from google.cloud._helpers import _datetime_from_microseconds # type: ignore -from google.cloud._helpers import _to_bytes # type: ignore +from google.api_core import exceptions # type: ignore +from google.api_core import retry # type: ignore +from google.cloud._helpers import _datetime_from_microseconds # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import bigtable as data_messages_v2_pb2 from google.cloud.bigtable_v2.types import data as data_v2_pb2 diff --git a/google/cloud/bigtable/row_filters.py b/google/cloud/bigtable/row_filters.py index 19af1b5e1..53192acc8 100644 --- a/google/cloud/bigtable/row_filters.py +++ b/google/cloud/bigtable/row_filters.py @@ -17,8 +17,8 @@ import struct -from google.cloud._helpers import _microseconds_from_datetime # type: ignore -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _microseconds_from_datetime # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import data as data_v2_pb2 _PACK_I64 = struct.Struct(">q").pack diff --git a/google/cloud/bigtable/row_set.py b/google/cloud/bigtable/row_set.py index f86faa02a..82a540b5a 100644 --- a/google/cloud/bigtable/row_set.py +++ b/google/cloud/bigtable/row_set.py @@ -15,7 +15,7 @@ """User-friendly container for Google Cloud Bigtable RowSet """ -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore class RowSet(object): diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index 6cf08ad38..30befe5c4 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -16,16 +16,16 @@ import warnings -from google.api_core import timeout # type: ignore -from google.api_core.exceptions import Aborted # type: ignore +from google.api_core import timeout # type: ignore +from google.api_core.exceptions import Aborted # type: ignore from google.api_core.exceptions import DeadlineExceeded from google.api_core.exceptions import NotFound from google.api_core.exceptions import RetryError from google.api_core.exceptions import ServiceUnavailable -from google.api_core.gapic_v1.method import DEFAULT # type: ignore -from google.api_core.retry import if_exception_type # type: ignore +from google.api_core.gapic_v1.method import DEFAULT # type: ignore +from google.api_core.retry import if_exception_type # type: ignore from google.api_core.retry import Retry -from google.cloud._helpers import _to_bytes # type: ignore +from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable.backup import Backup from google.cloud.bigtable.column_family import _gc_rule_from_pb from google.cloud.bigtable.column_family import ColumnFamily diff --git a/noxfile.py b/noxfile.py index 15117ee22..677d80c1f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -38,6 +38,7 @@ "unit", "system_emulated", "system", + "mypy", "cover", "lint", "lint_setup_py", @@ -79,6 +80,15 @@ def lint_setup_py(session): session.run("python", "setup.py", "check", "--restructuredtext", "--strict") + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def mypy(session): + """Verify type hints are mypy compatible.""" + session.install("-e", ".") + session.install("mypy") + session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") + + def default(session): # Install all test dependencies, then install this package in-place. diff --git a/owlbot.py b/owlbot.py index bacfdfbd1..109b329ac 100644 --- a/owlbot.py +++ b/owlbot.py @@ -149,10 +149,41 @@ def system_emulated(session): """nox.options.sessions = [ "unit", "system_emulated", - "system",""", + "system", + "mypy", + "pytype",""", ) +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" + ) + + session.run( + "mypy", + "-p", + "google.cloud.bigtable", + "--no-incremental" + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): +''', +) + # ---------------------------------------------------------------------------- # Samples templates # ---------------------------------------------------------------------------- From 3d62bab84cb7fe33883c7ab61001f05e2518c796 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 13 Oct 2021 20:48:06 +0000 Subject: [PATCH 06/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/noxfile.py b/noxfile.py index 677d80c1f..53e39a961 100644 --- a/noxfile.py +++ b/noxfile.py @@ -39,6 +39,7 @@ "system_emulated", "system", "mypy", + "pytype", "cover", "lint", "lint_setup_py", @@ -73,22 +74,23 @@ def blacken(session): ) -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install("docutils", "pygments") - session.run("python", "setup.py", "check", "--restructuredtext", "--strict") - - - @nox.session(python=DEFAULT_PYTHON_VERSION) def mypy(session): """Verify type hints are mypy compatible.""" + session.install("-e", ".") session.install("mypy") + session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install("docutils", "pygments") + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") + + def default(session): # Install all test dependencies, then install this package in-place. From 781784e1038ad412457d5ec1fb5924dc2d53073e Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 13:59:40 -0700 Subject: [PATCH 07/20] chore: simplify type of __version__ --- google/cloud/bigtable/__init__.py | 2 ++ google/cloud/bigtable/client.py | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/google/cloud/bigtable/__init__.py b/google/cloud/bigtable/__init__.py index bb48d5d98..8513c0ebb 100644 --- a/google/cloud/bigtable/__init__.py +++ b/google/cloud/bigtable/__init__.py @@ -15,8 +15,10 @@ """Google Cloud Bigtable API package.""" +from typing import Optional import pkg_resources # type: ignore +__version__ : Optional[str] try: __version__ = pkg_resources.get_distribution("google-cloud-bigtable").version except pkg_resources.DistributionNotFound: diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index d9b6441e7..a58d0aaf2 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -30,10 +30,6 @@ import os import warnings import grpc # type: ignore -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - __version__: str from google.api_core.gapic_v1 import client_info # type: ignore import google.auth # type: ignore @@ -49,7 +45,7 @@ BigtableTableAdminGrpcTransport, ) -from google.cloud.bigtable import __version__ # type: ignore +from google.cloud.bigtable import __version__ from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.cluster import Cluster From 9b13a6874bef4159be1ad36e6328d72470d8529a Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 13 Oct 2021 21:01:53 +0000 Subject: [PATCH 08/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- google/cloud/bigtable/__init__.py | 2 +- google/cloud/bigtable/client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google/cloud/bigtable/__init__.py b/google/cloud/bigtable/__init__.py index 8513c0ebb..49a72de54 100644 --- a/google/cloud/bigtable/__init__.py +++ b/google/cloud/bigtable/__init__.py @@ -18,7 +18,7 @@ from typing import Optional import pkg_resources # type: ignore -__version__ : Optional[str] +__version__: Optional[str] try: __version__ = pkg_resources.get_distribution("google-cloud-bigtable").version except pkg_resources.DistributionNotFound: diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index a58d0aaf2..7f9f6bd09 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -45,7 +45,7 @@ BigtableTableAdminGrpcTransport, ) -from google.cloud.bigtable import __version__ +from google.cloud.bigtable import __version__ from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.cluster import Cluster From a93d6197c3b1df77ef9e3bfa80dfaa5108e4d9da Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 18:09:09 -0700 Subject: [PATCH 09/20] chore: expand typing verification to google namespace --- google/cloud/__init__.py | 6 ++++-- google/cloud/bigtable/__init__.py | 4 ++-- google/cloud/bigtable/client.py | 2 +- google/cloud/bigtable/table.py | 13 +++++++------ noxfile.py | 5 ++--- owlbot.py | 14 +++----------- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py index 5e80aa293..ced5017a1 100644 --- a/google/cloud/__init__.py +++ b/google/cloud/__init__.py @@ -1,8 +1,10 @@ +from typing import List + try: - import pkg_resources # type: ignore + import pkg_resources pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) + __path__: List[str] = pkgutil.extend_path(__path__, __name__) diff --git a/google/cloud/bigtable/__init__.py b/google/cloud/bigtable/__init__.py index 8513c0ebb..b488c272c 100644 --- a/google/cloud/bigtable/__init__.py +++ b/google/cloud/bigtable/__init__.py @@ -16,9 +16,9 @@ from typing import Optional -import pkg_resources # type: ignore +import pkg_resources -__version__ : Optional[str] +__version__: Optional[str] try: __version__ = pkg_resources.get_distribution("google-cloud-bigtable").version except pkg_resources.DistributionNotFound: diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index a58d0aaf2..7f9f6bd09 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -45,7 +45,7 @@ BigtableTableAdminGrpcTransport, ) -from google.cloud.bigtable import __version__ +from google.cloud.bigtable import __version__ from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.cluster import Cluster diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index 30befe5c4..4b6dd01a1 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -1043,10 +1043,6 @@ class _RetryableMutateRowsWorker(object): are retryable, any subsequent call on this callable will be a no-op. """ - RETRY_CODES = tuple( - retryable.grpc_status_code.value[0] for retryable in RETRYABLE_MUTATION_ERRORS - ) - def __init__(self, client, table_name, rows, app_profile_id=None, timeout=None): self.client = client self.table_name = table_name @@ -1083,7 +1079,12 @@ def __call__(self, retry=DEFAULT_RETRY): @staticmethod def _is_retryable(status): - return status is None or status.code in _RetryableMutateRowsWorker.RETRY_CODES + RETRY_CODES = tuple( + retryable.grpc_status_code.value[0] + for retryable in RETRYABLE_MUTATION_ERRORS + ) + + return status is None or status.code in RETRY_CODES def _do_mutate_retryable_rows(self): """Mutate all the rows that are eligible for retry. @@ -1128,7 +1129,7 @@ def _do_mutate_retryable_rows(self): **kwargs ) except RETRYABLE_MUTATION_ERRORS: - # If an exception, considered retryable by `RETRY_CODES`, is + # If an exception, considered retryable by `RETRYABLE_MUTATION_ERRORS`, is # returned from the initial call, consider # it to be retryable. Wrap as a Bigtable Retryable Error. raise _BigtableRetryableError diff --git a/noxfile.py b/noxfile.py index 53e39a961..95c5c003a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -77,10 +77,9 @@ def blacken(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def mypy(session): """Verify type hints are mypy compatible.""" - session.install("-e", ".") - session.install("mypy") - + session.install("mypy", "types-setuptools") + # TODO: also verify types on tests session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") diff --git a/owlbot.py b/owlbot.py index 109b329ac..ea6f5b963 100644 --- a/owlbot.py +++ b/owlbot.py @@ -165,18 +165,10 @@ 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" - ) - - session.run( - "mypy", - "-p", - "google.cloud.bigtable", - "--no-incremental" - ) + session.install("mypy", "types-setuptools") + # TODO: also verify types on tests + session.run("mypy", "-p", "google", "--no-incremental") @nox.session(python=DEFAULT_PYTHON_VERSION) From daf4ebeedc3e123d45ed7dec7f66ac66d695089d Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 14 Oct 2021 01:11:22 +0000 Subject: [PATCH 10/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 95c5c003a..be9a7fc5d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -80,7 +80,7 @@ def mypy(session): session.install("-e", ".") session.install("mypy", "types-setuptools") # TODO: also verify types on tests - session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") + session.run("mypy", "-p", "google", "--no-incremental") @nox.session(python=DEFAULT_PYTHON_VERSION) From 3be3a4370ab411c7c8a1fd796dfa77a543e1e3e7 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 18:14:01 -0700 Subject: [PATCH 11/20] chore: remove ignores on api_core module --- google/cloud/bigtable/app_profile.py | 2 +- google/cloud/bigtable/client.py | 2 +- google/cloud/bigtable/cluster.py | 2 +- google/cloud/bigtable/instance.py | 2 +- google/cloud/bigtable/policy.py | 2 +- google/cloud/bigtable/row_data.py | 4 ++-- google/cloud/bigtable/table.py | 8 ++++---- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/google/cloud/bigtable/app_profile.py b/google/cloud/bigtable/app_profile.py index 665a578fb..5d6dbdb81 100644 --- a/google/cloud/bigtable/app_profile.py +++ b/google/cloud/bigtable/app_profile.py @@ -20,7 +20,7 @@ from google.cloud.bigtable.enums import RoutingPolicyType from google.cloud.bigtable_admin_v2.types import instance from google.protobuf import field_mask_pb2 -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound _APP_PROFILE_NAME_RE = re.compile( r"^projects/(?P[^/]+)/" diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index 7f9f6bd09..c9b92159f 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -31,7 +31,7 @@ import warnings import grpc # type: ignore -from google.api_core.gapic_v1 import client_info # type: ignore +from google.api_core.gapic_v1 import client_info import google.auth # type: ignore from google.auth.credentials import AnonymousCredentials # type: ignore diff --git a/google/cloud/bigtable/cluster.py b/google/cloud/bigtable/cluster.py index 82fcc24d8..f3e79c6c2 100644 --- a/google/cloud/bigtable/cluster.py +++ b/google/cloud/bigtable/cluster.py @@ -17,7 +17,7 @@ import re from google.cloud.bigtable_admin_v2.types import instance -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound _CLUSTER_NAME_RE = re.compile( diff --git a/google/cloud/bigtable/instance.py b/google/cloud/bigtable/instance.py index 9bd78d00b..9c22aaa79 100644 --- a/google/cloud/bigtable/instance.py +++ b/google/cloud/bigtable/instance.py @@ -26,7 +26,7 @@ from google.iam.v1 import options_pb2 # type: ignore -from google.api_core.exceptions import NotFound # type: ignore +from google.api_core.exceptions import NotFound from google.cloud.bigtable.policy import Policy diff --git a/google/cloud/bigtable/policy.py b/google/cloud/bigtable/policy.py index 7ce917a19..8396642fb 100644 --- a/google/cloud/bigtable/policy.py +++ b/google/cloud/bigtable/policy.py @@ -14,7 +14,7 @@ import base64 -from google.api_core.iam import Policy as BasePolicy # type: ignore +from google.api_core.iam import Policy as BasePolicy from google.cloud._helpers import _to_bytes # type: ignore from google.iam.v1 import policy_pb2 # type: ignore diff --git a/google/cloud/bigtable/row_data.py b/google/cloud/bigtable/row_data.py index 59b60a58b..6ab1188a8 100644 --- a/google/cloud/bigtable/row_data.py +++ b/google/cloud/bigtable/row_data.py @@ -19,8 +19,8 @@ import grpc # type: ignore -from google.api_core import exceptions # type: ignore -from google.api_core import retry # type: ignore +from google.api_core import exceptions +from google.api_core import retry from google.cloud._helpers import _datetime_from_microseconds # type: ignore from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable_v2.types import bigtable as data_messages_v2_pb2 diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index 4b6dd01a1..e7fced815 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -16,14 +16,14 @@ import warnings -from google.api_core import timeout # type: ignore -from google.api_core.exceptions import Aborted # type: ignore +from google.api_core import timeout +from google.api_core.exceptions import Aborted from google.api_core.exceptions import DeadlineExceeded from google.api_core.exceptions import NotFound from google.api_core.exceptions import RetryError from google.api_core.exceptions import ServiceUnavailable -from google.api_core.gapic_v1.method import DEFAULT # type: ignore -from google.api_core.retry import if_exception_type # type: ignore +from google.api_core.gapic_v1.method import DEFAULT +from google.api_core.retry import if_exception_type from google.api_core.retry import Retry from google.cloud._helpers import _to_bytes # type: ignore from google.cloud.bigtable.backup import Backup From 0ad8008359c2f6f9eba2c573b57eecb628e8927e Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Wed, 13 Oct 2021 18:23:04 -0700 Subject: [PATCH 12/20] chore: no pytype --- noxfile.py | 1 - owlbot.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index be9a7fc5d..8c14f4c66 100644 --- a/noxfile.py +++ b/noxfile.py @@ -39,7 +39,6 @@ "system_emulated", "system", "mypy", - "pytype", "cover", "lint", "lint_setup_py", diff --git a/owlbot.py b/owlbot.py index ea6f5b963..8efac06b4 100644 --- a/owlbot.py +++ b/owlbot.py @@ -150,8 +150,7 @@ def system_emulated(session): "unit", "system_emulated", "system", - "mypy", - "pytype",""", + "mypy",""", ) From 21cf1f3d3b99902d8a562fbdf9ef9da6448e7ce6 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Thu, 14 Oct 2021 09:28:23 -0700 Subject: [PATCH 13/20] chore: scope to just google.cloud.bigtable, defer fixing errors on broader package --- noxfile.py | 4 ++-- owlbot.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8c14f4c66..206e146f4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -78,8 +78,8 @@ def mypy(session): """Verify type hints are mypy compatible.""" session.install("-e", ".") session.install("mypy", "types-setuptools") - # TODO: also verify types on tests - session.run("mypy", "-p", "google", "--no-incremental") + # TODO: also verify types on tests, all of google package + session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") @nox.session(python=DEFAULT_PYTHON_VERSION) diff --git a/owlbot.py b/owlbot.py index 8efac06b4..054a88207 100644 --- a/owlbot.py +++ b/owlbot.py @@ -166,7 +166,7 @@ def mypy(session): """Verify type hints are mypy compatible.""" session.install("-e", ".") session.install("mypy", "types-setuptools") - # TODO: also verify types on tests + # TODO: also verify types on tests, all of google package session.run("mypy", "-p", "google", "--no-incremental") From e3b497e0cfbdfdc845cce80d448da0528ff78332 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 14 Oct 2021 16:30:16 +0000 Subject: [PATCH 14/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 206e146f4..817ac418f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -79,7 +79,7 @@ def mypy(session): session.install("-e", ".") session.install("mypy", "types-setuptools") # TODO: also verify types on tests, all of google package - session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") + session.run("mypy", "-p", "google", "--no-incremental") @nox.session(python=DEFAULT_PYTHON_VERSION) From 09ddb7fc302e16cef655e989f536b417b2349a55 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Thu, 14 Oct 2021 09:36:48 -0700 Subject: [PATCH 15/20] chore: fix template --- owlbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owlbot.py b/owlbot.py index 054a88207..438628413 100644 --- a/owlbot.py +++ b/owlbot.py @@ -167,7 +167,7 @@ def mypy(session): session.install("-e", ".") session.install("mypy", "types-setuptools") # TODO: also verify types on tests, all of google package - session.run("mypy", "-p", "google", "--no-incremental") + session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") @nox.session(python=DEFAULT_PYTHON_VERSION) From a382edb1d99749bb2658030fbb04ba41846a58d9 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 14 Oct 2021 16:38:53 +0000 Subject: [PATCH 16/20] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 817ac418f..206e146f4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -79,7 +79,7 @@ def mypy(session): session.install("-e", ".") session.install("mypy", "types-setuptools") # TODO: also verify types on tests, all of google package - session.run("mypy", "-p", "google", "--no-incremental") + session.run("mypy", "-p", "google.cloud.bigtable", "--no-incremental") @nox.session(python=DEFAULT_PYTHON_VERSION) From d428a0d4314e3bd47cd7f120b9672dededadf920 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Thu, 14 Oct 2021 09:56:54 -0700 Subject: [PATCH 17/20] chore: lint --- google/cloud/bigtable/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/google/cloud/bigtable/__init__.py b/google/cloud/bigtable/__init__.py index b488c272c..a54096624 100644 --- a/google/cloud/bigtable/__init__.py +++ b/google/cloud/bigtable/__init__.py @@ -18,6 +18,8 @@ from typing import Optional import pkg_resources +from google.cloud.bigtable.client import Client + __version__: Optional[str] try: __version__ = pkg_resources.get_distribution("google-cloud-bigtable").version @@ -25,7 +27,4 @@ __version__ = None -from google.cloud.bigtable.client import Client - - __all__ = ["__version__", "Client"] From 6d9a11770b2da7ee6100aa5bd7f190865f503b8d Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 14 Oct 2021 16:09:37 -0400 Subject: [PATCH 18/20] fix: break circular import Remove '_CLIENT_INFO' from module scope. --- google/cloud/bigtable/client.py | 11 +++++++---- tests/unit/test_client.py | 12 ++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/google/cloud/bigtable/client.py b/google/cloud/bigtable/client.py index c9b92159f..c50c20b0f 100644 --- a/google/cloud/bigtable/client.py +++ b/google/cloud/bigtable/client.py @@ -31,7 +31,7 @@ import warnings import grpc # type: ignore -from google.api_core.gapic_v1 import client_info +from google.api_core.gapic_v1 import client_info as client_info_lib import google.auth # type: ignore from google.auth.credentials import AnonymousCredentials # type: ignore @@ -45,7 +45,7 @@ BigtableTableAdminGrpcTransport, ) -from google.cloud.bigtable import __version__ +from google.cloud import bigtable from google.cloud.bigtable.instance import Instance from google.cloud.bigtable.cluster import Cluster @@ -59,7 +59,6 @@ INSTANCE_TYPE_PRODUCTION = instance.Instance.Type.PRODUCTION INSTANCE_TYPE_DEVELOPMENT = instance.Instance.Type.DEVELOPMENT INSTANCE_TYPE_UNSPECIFIED = instance.Instance.Type.TYPE_UNSPECIFIED -_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__) SPANNER_ADMIN_SCOPE = "https://www.googleapis.com/auth/spanner.admin" ADMIN_SCOPE = "https://www.googleapis.com/auth/bigtable.admin" """Scope for interacting with the Cluster Admin and Table Admin APIs.""" @@ -155,11 +154,15 @@ def __init__( credentials=None, read_only=False, admin=False, - client_info=_CLIENT_INFO, + client_info=None, client_options=None, admin_client_options=None, channel=None, ): + if client_info is None: + client_info = client_info_lib.ClientInfo( + client_library_version=bigtable.__version__, + ) if read_only and admin: raise ValueError( "A read-only client cannot also perform" "administrative actions." diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index b80290e4f..f6cd7a5cc 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -112,7 +112,8 @@ def _make_one(self, *args, **kwargs): @mock.patch("os.environ", {}) def test_constructor_defaults(self): - from google.cloud.bigtable.client import _CLIENT_INFO + from google.api_core import client_info + from google.cloud.bigtable import __version__ from google.cloud.bigtable.client import DATA_SCOPE credentials = _make_credentials() @@ -125,7 +126,8 @@ def test_constructor_defaults(self): self.assertIs(client._credentials, credentials.with_scopes.return_value) self.assertFalse(client._read_only) self.assertFalse(client._admin) - self.assertIs(client._client_info, _CLIENT_INFO) + self.assertIsInstance(client._client_info, client_info.ClientInfo) + self.assertEqual(client._client_info.client_library_version, __version__) self.assertIsNone(client._channel) self.assertIsNone(client._emulator_host) self.assertEqual(client.SCOPE, (DATA_SCOPE,)) @@ -399,7 +401,6 @@ def test_project_path_property(self): self.assertEqual(client.project_path, project_name) def test_table_data_client_not_initialized(self): - from google.cloud.bigtable.client import _CLIENT_INFO from google.cloud.bigtable_v2 import BigtableClient credentials = _make_credentials() @@ -407,7 +408,6 @@ def test_table_data_client_not_initialized(self): table_data_client = client.table_data_client self.assertIsInstance(table_data_client, BigtableClient) - self.assertIs(client._client_info, _CLIENT_INFO) self.assertIs(client._table_data_client, table_data_client) def test_table_data_client_not_initialized_w_client_info(self): @@ -466,7 +466,6 @@ def test_table_admin_client_not_initialized_no_admin_flag(self): client.table_admin_client() def test_table_admin_client_not_initialized_w_admin_flag(self): - from google.cloud.bigtable.client import _CLIENT_INFO from google.cloud.bigtable_admin_v2 import BigtableTableAdminClient credentials = _make_credentials() @@ -476,7 +475,6 @@ def test_table_admin_client_not_initialized_w_admin_flag(self): table_admin_client = client.table_admin_client self.assertIsInstance(table_admin_client, BigtableTableAdminClient) - self.assertIs(client._client_info, _CLIENT_INFO) self.assertIs(client._table_admin_client, table_admin_client) def test_table_admin_client_not_initialized_w_client_info(self): @@ -537,7 +535,6 @@ def test_instance_admin_client_not_initialized_no_admin_flag(self): client.instance_admin_client() def test_instance_admin_client_not_initialized_w_admin_flag(self): - from google.cloud.bigtable.client import _CLIENT_INFO from google.cloud.bigtable_admin_v2 import BigtableInstanceAdminClient credentials = _make_credentials() @@ -547,7 +544,6 @@ def test_instance_admin_client_not_initialized_w_admin_flag(self): instance_admin_client = client.instance_admin_client self.assertIsInstance(instance_admin_client, BigtableInstanceAdminClient) - self.assertIs(client._client_info, _CLIENT_INFO) self.assertIs(client._instance_admin_client, instance_admin_client) def test_instance_admin_client_not_initialized_w_client_info(self): From fbdc35485b2d70a2f2f9e93aac8b4cac3eafbfb6 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 14 Oct 2021 16:39:13 -0400 Subject: [PATCH 19/20] fix: unsnarl typing around list of retryable status codes --- google/cloud/bigtable/table.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index e7fced815..1dd8a7751 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -14,6 +14,7 @@ """User-friendly container for Google Cloud Bigtable Table.""" +from typing import Set import warnings from google.api_core import timeout @@ -57,6 +58,12 @@ RETRYABLE_MUTATION_ERRORS = (Aborted, DeadlineExceeded, ServiceUnavailable) """Errors which can be retried during row mutation.""" +RETRYABLE_CODES: Set[int] = set() + +for retryable in RETRYABLE_MUTATION_ERRORS: + if retryable.grpc_status_code is not None: + RETRYABLE_CODES.add(retryable.grpc_status_code.value[0]) + class _BigtableRetryableError(Exception): """Retry-able error expected by the default retry strategy.""" @@ -1079,12 +1086,7 @@ def __call__(self, retry=DEFAULT_RETRY): @staticmethod def _is_retryable(status): - RETRY_CODES = tuple( - retryable.grpc_status_code.value[0] - for retryable in RETRYABLE_MUTATION_ERRORS - ) - - return status is None or status.code in RETRY_CODES + return status is None or status.code in RETRYABLE_CODES def _do_mutate_retryable_rows(self): """Mutate all the rows that are eligible for retry. From 65a472bd975972c818b0e3eea6ccec62f48f0e8e Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 14 Oct 2021 17:26:21 -0400 Subject: [PATCH 20/20] ci: fix coverage gap induced by typing --- google/cloud/bigtable/table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/cloud/bigtable/table.py b/google/cloud/bigtable/table.py index 1dd8a7751..fddd04809 100644 --- a/google/cloud/bigtable/table.py +++ b/google/cloud/bigtable/table.py @@ -61,7 +61,7 @@ RETRYABLE_CODES: Set[int] = set() for retryable in RETRYABLE_MUTATION_ERRORS: - if retryable.grpc_status_code is not None: + if retryable.grpc_status_code is not None: # pragma: NO COVER RETRYABLE_CODES.add(retryable.grpc_status_code.value[0])