Skip to content

Commit

Permalink
cleans up type hints and some minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
chalmerlowe committed Jan 10, 2025
1 parent 840b5ea commit de2b7a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
21 changes: 10 additions & 11 deletions google/cloud/bigquery/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
from __future__ import annotations
import collections
import enum
import typing
from typing import Any, cast, Dict, Iterable, Optional, Union

from google.cloud.bigquery import _helpers
from google.cloud.bigquery import standard_sql
from google.cloud.bigquery._helpers import (
_isinstance_or_raise,
)
from google.cloud.bigquery.enums import StandardSqlTypeNames


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

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

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

return self._properties.get("serializationLibrary")
return typing.cast(str, self._properties.get("serializationLibrary"))

@serialization_library.setter
def serialization_library(self, value: str):
value = _isinstance_or_raise(value, str, none_allowed=False)
value = _helpers._isinstance_or_raise(value, str, none_allowed=False)
self._properties["serializationLibrary"] = value

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

return self._properties.get("name")

@name.setter
def name(self, value: Optional[str] = None):
value = _isinstance_or_raise(value, str, none_allowed=True)
value = _helpers._isinstance_or_raise(value, str, none_allowed=True)
self._properties["name"] = value

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

return self._properties.get("parameters")

@parameters.setter
def parameters(self, value: Optional[dict[str, str]] = None):
value = _isinstance_or_raise(value, dict, none_allowed=True)
value = _helpers._isinstance_or_raise(value, dict, none_allowed=True)
self._properties["parameters"] = value

def to_api_repr(self) -> dict:
Expand Down
12 changes: 3 additions & 9 deletions tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

from google.cloud import bigquery
from google.cloud.bigquery.standard_sql import StandardSqlStructType
from google.cloud.bigquery.schema import (
PolicyTagList,
SerDeInfo,
)
from google.cloud.bigquery import schema
from google.cloud.bigquery.schema import PolicyTagList


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

def test_to_api_repr(self):
from google.cloud.bigquery.schema import PolicyTagList

policy = PolicyTagList(names=("foo", "bar"))
self.assertEqual(
policy.to_api_repr(),
Expand Down Expand Up @@ -889,8 +885,6 @@ def test_valid_mapping_representation(self):
class TestPolicyTags(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.bigquery.schema import PolicyTagList

return PolicyTagList

def _make_one(self, *args, **kw):
Expand Down Expand Up @@ -1139,7 +1133,7 @@ class TestSerDeInfo:

@staticmethod
def _get_target_class():
return SerDeInfo
return schema.SerDeInfo

def _make_one(self, *args, **kwargs):
return self._get_target_class()(*args, **kwargs)
Expand Down

0 comments on commit de2b7a4

Please sign in to comment.