Skip to content

Commit e5d7e83

Browse files
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.
1 parent d92b487 commit e5d7e83

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

google/cloud/bigquery/external_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ def schema(self):
837837
"""
838838
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
839839
# 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
840+
prop: Dict[str, Any] = self._properties.get("schema", {})
841+
return [SchemaField.from_api_repr(field) for field in prop.get("fields", [])]
842842

843843
@schema.setter
844844
def schema(self, value):

google/cloud/bigquery/job/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def configuration(self) -> _JobConfig:
437437
"""Job-type specific configurtion."""
438438
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
439439
# manage a pytype issue that came up in another PR. See Issue: #2132
440-
configuration = self._CONFIG_CLASS() # pytype: disable=not-callable
440+
configuration: _JobConfig = self._CONFIG_CLASS() # pytype: disable=not-callable
441441
configuration._properties = self._properties.setdefault("configuration", {})
442442
return configuration
443443

google/cloud/bigquery/routine/routine.py

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

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

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

539539
@property
540540
def path(self):

google/cloud/bigquery/schema.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ def __init__(
234234
if policy_tags is not _DEFAULT_VALUE:
235235
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
236236
# manage a pytype issue that came up in another PR. See Issue: #2132
237-
self._properties["policyTags"] = (
238-
policy_tags.to_api_repr() # pytype: disable=attribute-error
239-
if policy_tags is not None
240-
else None
241-
)
237+
self._properties["policyTags"] = policy_tags.to_api_repr() if policy_tags is not None else None
242238
if isinstance(range_element_type, str):
243239
self._properties["rangeElementType"] = {"type": range_element_type}
244240
if isinstance(range_element_type, FieldElementType):

google/cloud/bigquery/table.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _reference_getter(table):
139139

140140
# TODO: The typehinting for this needs work. Setting this pragma to temporarily
141141
# manage a pytype issue that came up in another PR. See Issue: #2132
142-
def _view_use_legacy_sql_getter(table):
142+
def _view_use_legacy_sql_getter(table: "Table") -> 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,10 +151,10 @@ 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":

0 commit comments

Comments
 (0)