From 88a83a0dff2bf5cb22db683e7f55f1acef8359c2 Mon Sep 17 00:00:00 2001 From: Ayush Shah Date: Mon, 11 Aug 2025 17:54:08 +0530 Subject: [PATCH] MINOR: Refactor BigQuery client type hinting in bigquery_utils.py (#22873) * Refactor BigQuery client type hinting in bigquery_utils.py - Updated type hint for the BigQuery client to use forward declaration for better compatibility with type checking. - Moved import statement for google.cloud.bigquery inside TYPE_CHECKING block to optimize imports during runtime. * Refactor BigQuery client import structure in bigquery_utils.py - Moved the import statement for google.cloud.bigquery inside the TYPE_CHECKING block to enhance type hinting compatibility. - Adjusted the import location for better runtime performance and adherence to best practices. --- ingestion/src/metadata/utils/bigquery_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ingestion/src/metadata/utils/bigquery_utils.py b/ingestion/src/metadata/utils/bigquery_utils.py index 000b4f487ae..5b972fd4eaf 100644 --- a/ingestion/src/metadata/utils/bigquery_utils.py +++ b/ingestion/src/metadata/utils/bigquery_utils.py @@ -14,9 +14,7 @@ Utils module of BigQuery """ from copy import deepcopy -from typing import List, Optional - -from google.cloud import bigquery +from typing import TYPE_CHECKING, List, Optional from metadata.generated.schema.entity.services.connections.database.bigQueryConnection import ( BigQueryConnection, @@ -34,6 +32,9 @@ from metadata.utils.credentials import ( get_gcp_impersonate_credentials, ) +if TYPE_CHECKING: + from google.cloud import bigquery + def get_bigquery_client( project_id: Optional[str] = None, @@ -42,7 +43,7 @@ def get_bigquery_client( quota_project_id: Optional[str] = None, scopes: Optional[List[str]] = None, lifetime: Optional[int] = 3600, -) -> bigquery.Client: +) -> "bigquery.Client": """Get a BigQuery client Args: @@ -65,6 +66,8 @@ def get_bigquery_client( scopes=scopes, lifetime=lifetime, ) + from google.cloud import bigquery # pylint: disable=import-outside-toplevel + return bigquery.Client( credentials=credentials, project=project_id, location=location )