8000 Fix: Update type hints for various BigQuery files (#2206) · googleapis/python-bigquery@b863291 · GitHub
[go: up one dir, main page]

Skip to content

Commit b863291

Browse files
Fix: Update type hints for various BigQuery files (#2206)
* Fix: Update type hints for various BigQuery files This commit addresses Issue #2132 by updating type hints in the following files: - google/cloud/bigquery/external_config.py - google/cloud/bigquery/job/base.py - google/cloud/bigquery/routine/routine.py - google/cloud/bigquery/schema.py - google/cloud/bigquery/table.py These changes improve code clarity and maintainability by providing more accurate type information. * updates type hints across the board --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent de33204 commit b863291

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

google/cloud/bigquery/external_config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import base64
2424
import copy
25+
import typing
2526
from typing import Any, Dict, FrozenSet, Iterable, Optional, Union
2627

2728
from google.cloud.bigquery._helpers import _to_bytes
@@ -835,10 +836,10 @@ def schema(self):
835836
See
836837
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.schema
837838
"""
838-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
839-
# manage a pytype issue that came up in another PR. See Issue: #2132
840-
prop = self._properties.get("schema", {}) # type: ignore
841-
return [SchemaField.from_api_repr(field) for field in prop.get("fields", [])] # type: ignore
839+
prop: Dict[str, Any] = typing.cast(
840+
Dict[str, Any], self._properties.get("schema", {})
841+
)
842+
return [SchemaField.from_api_repr(field) for field in prop.get("fields", [])]
842843

843844
@schema.setter
844845
def schema(self, value):

google/cloud/bigquery/job/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,7 @@ def __init__(self, job_id, client):
435435
@property
436436
def configuration(self) -> _JobConfig:
437437
"""Job-type specific configurtion."""
438-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
439-
# manage a pytype issue that came up in another PR. See Issue: #2132
440-
configuration = self._CONFIG_CLASS() # pytype: disable=not-callable
438+
configuration: _JobConfig = self._CONFIG_CLASS() # pytype: disable=not-callable
441439
configuration._properties = self._properties.setdefault("configuration", {})
442440
return configuration
443441

google/cloud/bigquery/routine/routine.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,23 +518,17 @@ def __init__(self):
518518
@property
519519
def project(self):
520520
"""str: ID of the project containing the routine."""
521-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
522-
# manage a pytype issue that came up in another PR. See Issue: #2132
523-
return self._properties["projectId"] # pytype: disable=typed-dict-error
521+
return self._properties.get("projectId", "")
524522

525523
@property
526524
def dataset_id(self):
527525
"""str: ID of dataset containing the routine."""
528-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
529-
# manage a pytype issue that came up in another PR. See Issue: #2132
530-
return self._properties["datasetId"] # pytype: disable=typed-dict-error
526+
return self._properties.get("datasetId", "")
531527

532528
@property
533529
def routine_id(self):
534530
"""str: The routine ID."""
535-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
536-
# manage a pytype issue that came up in another PR. See Issue: #2132
537-
return self._properties["routineId"] # pytype: disable=typed-dict-error
531+
return self._properties.get("routineId", "")
538532

539533
@property
540534
def path(self):

google/cloud/bigquery/schema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,9 @@ def __init__(
232232
if max_length is not _DEFAULT_VALUE:
233233
self._properties["maxLength"] = max_length
234234
if policy_tags is not _DEFAULT_VALUE:
235-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
236-
# manage a pytype issue that came up in another PR. See Issue: #2132
237235
self._properties["policyTags"] = (
238-
policy_tags.to_api_repr() # pytype: disable=attribute-error
239-
if policy_tags is not None
236+
policy_tags.to_api_repr()
237+
if isinstance(policy_tags, PolicyTagList)
240238
else None
241239
)
242240
if isinstance(range_element_type, str):

google/cloud/bigquery/table.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def _reference_getter(table):
137137
return TableReference(dataset_ref, table.table_id)
138138

139139

140-
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
141-
# manage a pytype issue that came up in another PR. See Issue: #2132
142-
def _view_use_legacy_sql_getter(table):
140+
def _view_use_legacy_sql_getter(
141+
table: Union["Table", "TableListItem"]
142+
) -> Optional[bool]:
143143
"""bool: Specifies whether to execute the view with Legacy or Standard SQL.
144144
145145
This boolean specifies whether to execute the view with Legacy SQL
@@ -151,15 +151,16 @@ def _view_use_legacy_sql_getter(table):
151151
ValueError: For invalid value types.
152152
"""
153153

154-
view = table._properties.get("view") # type: ignore
154+
view: Optional[Dict[str, Any]] = table._properties.get("view")
155155
if view is not None:
156156
# The server-side default for useLegacySql is True.
157-
return view.get("useLegacySql", True) # type: ignore
157+
return view.get("useLegacySql", True) if view is not None else True
158158
# In some cases, such as in a table list no view object is present, but the
159159
# resource still represents a view. Use the type as a fallback.
160160
if table.table_type == "VIEW":
161161
# The server-side default for useLegacySql is True.
162162
return True
163+
return None # explicit return statement to appease mypy
163164

164165

165166
class _TableBase:

0 commit comments

Comments
 (0)
0