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.
This commit is contained in:
Ayush Shah 2025-08-11 17:54:08 +05:30
parent dd7682a3b5
commit 88a83a0dff

View File

@ -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
)