Skip to content

Commit

Permalink
sort and appease mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richmond committed Feb 21, 2023
1 parent b27f6d8 commit 54897ff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
20 changes: 10 additions & 10 deletions airflow/providers/google/cloud/hooks/bigtable.py
Expand Up @@ -22,12 +22,11 @@
import warnings
from typing import Sequence

from google.cloud.bigtable import Client
from google.cloud.bigtable import Client, enums
from google.cloud.bigtable.cluster import Cluster
from google.cloud.bigtable.column_family import ColumnFamily, GarbageCollectionRule
from google.cloud.bigtable.instance import Instance
from google.cloud.bigtable.table import ClusterState, Table
from google.cloud.bigtable import enums

from airflow.providers.google.common.consts import CLIENT_INFO
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
Expand Down Expand Up @@ -56,9 +55,9 @@ def __init__(
delegate_to=delegate_to,
impersonation_chain=impersonation_chain,
)
self._client = None
self._client: Client | None = None

def _get_client(self, project_id: str):
def _get_client(self, project_id: str) -> Client:
if not self._client:
self._client = Client(
project=project_id,
Expand All @@ -69,7 +68,7 @@ def _get_client(self, project_id: str):
return self._client

@GoogleBaseHook.fallback_to_default_project_id
def get_instance(self, instance_id: str, project_id: str) -> Instance:
def get_instance(self, instance_id: str, project_id: str) -> Instance | None:
"""
Retrieves and returns the specified Cloud Bigtable instance if it exists.
Otherwise, returns None.
Expand Down Expand Up @@ -113,10 +112,10 @@ def create_instance(
project_id: str,
replica_clusters: list[dict[str, str]] | None = None,
instance_display_name: str | None = None,
instance_type: enums.Instance.Type = enums.Instance.Type.UNSPECIFIED,
instance_type: enums.Instance.Type = enums.Instance.Type.UNSPECIFIED, # type: ignore[assignment]
instance_labels: dict | None = None,
cluster_nodes: int | None = None,
cluster_storage_type: enums.StorageType = enums.StorageType.UNSPECIFIED,
cluster_storage_type: enums.StorageType = enums.StorageType.UNSPECIFIED, # type: ignore[assignment]
timeout: float | None = None,
) -> Instance:
"""
Expand All @@ -142,7 +141,6 @@ def create_instance(
:param timeout: (optional) timeout (in seconds) for instance creation.
If None is not specified, Operator will wait indefinitely.
"""

instance = Instance(
instance_id,
self._get_client(project_id=project_id),
Expand Down Expand Up @@ -198,7 +196,6 @@ def update_instance(
:param timeout: (optional) timeout (in seconds) for instance update.
If None is not specified, Operator will wait indefinitely.
"""

instance = Instance(
instance_id=instance_id,
client=self._get_client(project_id=project_id),
Expand Down Expand Up @@ -250,7 +247,10 @@ def delete_table(self, instance_id: str, table_id: str, project_id: str) -> None
BigTable exists. If set to None or missing,
the default project_id from the Google Cloud connection is used.
"""
table = self.get_instance(instance_id=instance_id, project_id=project_id).table(table_id=table_id)
instance = self.get_instance(instance_id=instance_id, project_id=project_id)
if instance is None:
raise RuntimeError("Instance %s did not exist; unable to delete table %s" % instance_id, table_id)
table = instance.table(table_id=table_id)
table.delete()

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/google/cloud/operators/bigtable.py
Expand Up @@ -22,8 +22,8 @@
from typing import TYPE_CHECKING, Iterable, Sequence

import google.api_core.exceptions
from google.cloud.bigtable.column_family import GarbageCollectionRule
from google.cloud.bigtable import enums
from google.cloud.bigtable.column_family import GarbageCollectionRule

from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/google/cloud/sensors/bigtable.py
Expand Up @@ -21,8 +21,8 @@
from typing import TYPE_CHECKING, Sequence

import google.api_core.exceptions
from google.cloud.bigtable.table import ClusterState
from google.cloud.bigtable import enums
from google.cloud.bigtable.table import ClusterState

from airflow.providers.google.cloud.hooks.bigtable import BigtableHook
from airflow.providers.google.cloud.links.bigtable import BigtableTablesLink
Expand Down Expand Up @@ -103,7 +103,7 @@ def poke(self, context: Context) -> bool:
)
return False

ready_state = ClusterState(enums.Table.ClusterState.ReplicationState.READY)
ready_state = ClusterState(enums.Table.ReplicationState.READY)

is_table_replicated = True
for cluster_id in cluster_states.keys():
Expand Down
3 changes: 1 addition & 2 deletions tests/providers/google/cloud/hooks/test_bigtable.py
Expand Up @@ -21,9 +21,8 @@
from unittest.mock import PropertyMock

import google
from google.cloud.bigtable import Client
from google.cloud.bigtable import Client, enums
from google.cloud.bigtable.instance import Instance
from google.cloud.bigtable import enums

from airflow.providers.google.cloud.hooks.bigtable import BigtableHook
from airflow.providers.google.common.consts import CLIENT_INFO
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/google/cloud/operators/test_bigtable.py
Expand Up @@ -21,9 +21,9 @@

import google.api_core.exceptions
import pytest
from google.cloud.bigtable import enums
from google.cloud.bigtable.column_family import MaxVersionsGCRule
from google.cloud.bigtable.instance import Instance
from google.cloud.bigtable import enums

from airflow.exceptions import AirflowException
from airflow.providers.google.cloud.operators.bigtable import (
Expand Down

0 comments on commit 54897ff

Please sign in to comment.