This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 324
feat: add type hints to Client #2044
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
14fd6a9
add type hints
rinarakaki a0a0f99
Merge branch 'main' into typing-client
chalmerlowe 624df2b
Merge branch 'main' into typing-client
rinarakaki a3c2b7f
Update client.py
chalmerlowe 9950656
Merge branch 'main' into typing-client
chalmerlowe a71e193
Update google/cloud/bigquery/client.py
chalmerlowe 701ef13
Update client.py
chalmerlowe 0f8af52
Update google/cloud/bigquery/client.py
chalmerlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
| ResumableTimeoutType = Union[ | ||
| None, float, Tuple[float, float] | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
|
chalmerlowe marked this conversation as resolved.
Outdated
|
||
| _DEFAULT_CHUNKSIZE = 100 * 1024 * 1024 # 100 MB | ||
| _MAX_MULTIPART_SIZE = 5 * 1024 * 1024 | ||
| _DEFAULT_NUM_RETRIES = 6 | ||
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious, why did we choose to:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| super(Client, self).__init__( | ||
| project=project, | ||
| credentials=credentials, | ||
|
|
@@ -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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.