Skip to content

Commit 4cd3df4

Browse files
committed
improve code
1 parent 657dd84 commit 4cd3df4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

google/cloud/bigquery/schema.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,8 @@ def from_api_repr(cls, api_repr: dict) -> "SchemaField":
270270
"""Return a ``SchemaField`` object deserialized from a dictionary.
271271
272272
Args:
273-
api_repr (Mapping[str, str]): The serialized representation
274-
of the SchemaField, such as what is output by
275-
:meth:`to_api_repr`.
273+
api_repr (dict): The serialized representation of the SchemaField,
274+
such as what is output by :meth:`to_api_repr`.
276275
277276
Returns:
278277
google.cloud.bigquery.schema.SchemaField: The ``SchemaField`` object.
@@ -282,11 +281,10 @@ def from_api_repr(cls, api_repr: dict) -> "SchemaField":
282281
# The API would return a string despite we send an integer. To ensure
283282
# success of resending received schema, we convert string to integer
284283
# to ensure consistency.
285-
if (
286-
isinstance(api_repr, dict)
287-
and type(api_repr.get("timestampPrecision")) is str
288-
):
284+
try:
289285
api_repr["timestampPrecision"] = int(api_repr["timestampPrecision"])
286+
except (TypeError, KeyError):
287+
pass
290288

291289
# Note: we don't make a copy of api_repr because this can cause
292290
# unnecessary slowdowns, especially on deeply nested STRUCT / RECORD

0 commit comments

Comments
 (0)