Skip to content

Commit de2b7a4

Browse files
committed
cleans up type hints and some minor tweaks
1 parent 840b5ea commit de2b7a4

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

google/cloud/bigquery/schema.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
from __future__ import annotations
1818
import collections
1919
import enum
20+
import typing
2021
from typing import Any, cast, Dict, Iterable, Optional, Union
2122

2223
from google.cloud.bigquery import _helpers
2324
from google.cloud.bigquery import standard_sql
24-
from google.cloud.bigquery._helpers import (
25-
_isinstance_or_raise,
26-
)
2725
from google.cloud.bigquery.enums import StandardSqlTypeNames
2826

2927

@@ -564,8 +562,9 @@ def to_api_repr(self) -> dict:
564562

565563
class SerDeInfo:
566564
"""Serializer and deserializer information.
565+
567566
Args:
568-
serializationLibrary (str): Required. Specifies a fully-qualified class
567+
serialization_library (str): Required. Specifies a fully-qualified class
569568
name of the serialization library that is responsible for the
570569
translation of data between table representation and the underlying
571570
low-level input and output format structures. The maximum length is
@@ -588,40 +587,40 @@ def __init__(
588587
self.parameters = parameters
589588

590589
@property
591-
def serialization_library(self) -> Any:
590+
def serialization_library(self) -> str:
592591
"""Required. Specifies a fully-qualified class name of the serialization
593592
library that is responsible for the translation of data between table
594593
representation and the underlying low-level input and output format
595594
structures. The maximum length is 256 characters."""
596595

597-
return self._properties.get("serializationLibrary")
596+
return typing.cast(str, self._properties.get("serializationLibrary"))
598597

599598
@serialization_library.setter
600599
def serialization_library(self, value: str):
601-
value = _isinstance_or_raise(value, str, none_allowed=False)
600+
value = _helpers._isinstance_or_raise(value, str, none_allowed=False)
602601
self._properties["serializationLibrary"] = value
603602

604603
@property
605-
def name(self) -> Any:
604+
def name(self) -> Optional[str]:
606605
"""Optional. Name of the SerDe. The maximum length is 256 characters."""
607606

608607
return self._properties.get("name")
609608

610609
@name.setter
611610
def name(self, value: Optional[str] = None):
612-
value = _isinstance_or_raise(value, str, none_allowed=True)
611+
value = _helpers._isinstance_or_raise(value, str, none_allowed=True)
613612
self._properties["name"] = value
614613

615614
@property
616-
def parameters(self) -> Any:
615+
def parameters(self) -> Optional[dict[str, str]]:
617616
"""Optional. Key-value pairs that define the initialization parameters
618617
for the serialization library. Maximum size 10 Kib."""
619618

620619
return self._properties.get("parameters")
621620

622621
@parameters.setter
623622
def parameters(self, value: Optional[dict[str, str]] = None):
624-
value = _isinstance_or_raise(value, dict, none_allowed=True)
623+
value = _helpers._isinstance_or_raise(value, dict, none_allowed=True)
625624
self._properties["parameters"] = value
626625

627626
def to_api_repr(self) -> dict:

tests/unit/test_schema.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
from google.cloud import bigquery
2222
from google.cloud.bigquery.standard_sql import StandardSqlStructType
23-
from google.cloud.bigquery.schema import (
24-
PolicyTagList,
25-
SerDeInfo,
26-
)
23+
from google.cloud.bigquery import schema
24+
from google.cloud.bigquery.schema import PolicyTagList
2725

2826

2927
class TestSchemaField(unittest.TestCase):
@@ -133,8 +131,6 @@ def test_constructor_range_str(self):
133131
self.assertEqual(field.range_element_type.element_type, "DATETIME")
134132

135133
def test_to_api_repr(self):
136-
from google.cloud.bigquery.schema import PolicyTagList
137-
138134
policy = PolicyTagList(names=("foo", "bar"))
139135
self.assertEqual(
140136
policy.to_api_repr(),
@@ -889,8 +885,6 @@ def test_valid_mapping_representation(self):
889885
class TestPolicyTags(unittest.TestCase):
890886
@staticmethod
891887
def _get_target_class():
892-
from google.cloud.bigquery.schema import PolicyTagList
893-
894888
return PolicyTagList
895889

896890
def _make_one(self, *args, **kw):
@@ -1139,7 +1133,7 @@ class TestSerDeInfo:
11391133

11401134
@staticmethod
11411135
def _get_target_class():
1142-
return SerDeInfo
1136+
return schema.SerDeInfo
11431137

11441138
def _make_one(self, *args, **kwargs):
11451139
return self._get_target_class()(*args, **kwargs)

0 commit comments

Comments
 (0)