Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import uuid
import warnings

import requests

from google import resumable_media # type: ignore
from google.resumable_media.requests import MultipartUpload # type: ignore
from google.resumable_media.requests import ResumableUpload
Expand All @@ -65,6 +67,7 @@
DEFAULT_BQSTORAGE_CLIENT_INFO = None # type: ignore


from google.auth.credentials import Credentials
from google.cloud.bigquery._http import Connection
from google.cloud.bigquery import _job_helpers
from google.cloud.bigquery import _pandas_helpers
Expand Down Expand Up @@ -122,9 +125,7 @@
from google.cloud.bigquery.table import RowIterator

pyarrow = _versions_helpers.PYARROW_VERSIONS.try_import()
pandas = (
_versions_helpers.PANDAS_VERSIONS.try_import()
) # mypy check fails because pandas import is outside module, there are type: ignore comments related to this
pandas = _versions_helpers.PANDAS_VERSIONS.try_import() # mypy check fails because pandas import is outside module, there are type: ignore comments related to this
Comment thread
chalmerlowe marked this conversation as resolved.
Outdated

ResumableTimeoutType = Union[
None, float, Tuple[float, float]
Expand All @@ -133,8 +134,7 @@
if typing.TYPE_CHECKING: # pragma: NO COVER
# os.PathLike is only subscriptable in Python 3.9+, thus shielding with a condition.
PathType = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
import requests # required by api-core


Comment thread
chalmerlowe marked this conversation as resolved.
Outdated
_DEFAULT_CHUNKSIZE = 100 * 1024 * 1024 # 100 MB
_MAX_MULTIPART_SIZE = 5 * 1024 * 1024
_DEFAULT_NUM_RETRIES = 6
Expand Down Expand Up @@ -231,15 +231,23 @@ class Client(ClientWithProject):

def __init__(
self,
project=None,
credentials=None,
_http=None,
location=None,
default_query_job_config=None,
default_load_job_config=None,
client_info=None,
client_options=None,
project: Optional[str] = None,
credentials: Optional[Credentials] = None,
_http: Optional[requests.Session] = None,
location: Optional[str] = None,
default_query_job_config: Optional[QueryJobConfig] = None,
default_load_job_config: Optional[LoadJobConfig] = None,
client_info: Optional[google.api_core.client_info.ClientInfo] = None,
client_options: Optional[
Union[google.api_core.client_options.ClientOptions, Dict[str, Any]]
] = None,
) -> None:
if client_options is None:
client_options = {}
if isinstance(client_options, dict):
client_options = google.api_core.client_options.from_dict(client_options)
assert isinstance(client_options, google.api_core.client_options.ClientOptions)

Comment on lines +244 to +252

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious, why did we choose to:

  • move this content from after the call to super() to before the call to super()? What is the reason for reordering this content?
  • add an assert statement when one was not used previously?

@rinarakaki rinarakaki Nov 22, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Moving this part before the call to super() is optional, but I did it because actually the exact same type check & coercion happens inside the super() (Client.__init__) as well, so I let it early break in the second time.
  • The reason for adding the assert statement is to let the type checker know the type of client_options, otherwise it wouldn't know that the if client_options.api_endpoint: expression at the line 261 is valid .

super(Client, self).__init__(
project=project,
credentials=credentials,
Expand All @@ -251,10 +259,6 @@ def __init__(
bq_host = _get_bigquery_host()
kw_args["api_endpoint"] = bq_host if bq_host != _DEFAULT_HOST else None
client_universe = None
if client_options is None:
client_options = {}
if isinstance(client_options, dict):
client_options = google.api_core.client_options.from_dict(client_options)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint
kw_args["api_endpoint"] = api_endpoint
Expand Down