Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
cleans up type hints and some minor tweaks
  • Loading branch information
chalmerlowe committed Jan 10, 2025
commit de2b7a4db4f7c3cb6e5247b6c90f6902b3c4bcac
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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the name in the REST API? I'd prefer the full names rather than abbreviations, but I'm OK with this if it's to be consistent with the proto/REST API.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SerDeInfo is the name in the proto/REST API definitions.

"""Serializer and deserializer information.

Args:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need a blank line here for the docs renderer to work?

Suggested change
"""Serializer and deserializer information.
Args:
"""Serializer and deserializer information.
Args:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think Required. should only apply to the init.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in chat, I prefer to leave this as is.

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."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: similarly, we can remove Optional. here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in chat, I prefer to leave this as is.


return self._properties.get("name")

@name.setter
def name(self, value: Optional[str] = None):
Comment thread
Linchin marked this conversation as resolved.
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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See reply above from Python Docs about the concept of optional versus typing.Optional.

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