Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 18523c4

Browse files
committed
updates comments, syntax formatting, linting
1 parent 6979a63 commit 18523c4

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

gapic/schema/wrappers.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,13 @@ def sample_request(self):
14781478
req[self.body] = {} # just an empty json.
14791479
return req
14801480

1481+
14811482
ENABLE_WRAPPER_TYPES_FOR_PAGE_SIZE = {
1482-
'google.cloud.bigquery.v2': True,
1483-
'google.cloud.bigquery.connection.v1beta1': False,
1483+
"google.cloud.bigquery.v2": True,
1484+
"google.cloud.bigquery.connection.v1beta1": False,
14841485
}
14851486

1487+
14861488
@dataclasses.dataclass(frozen=True)
14871489
class Method:
14881490
"""Description of a method (defined with the ``rpc`` keyword)."""
@@ -1499,6 +1501,8 @@ class Method:
14991501
default_factory=metadata.Metadata,
15001502
)
15011503

1504+
PACKAGES_WITH_ALLOWED_WRAPPERS = {"google.cloud.bigquery.v2"}
1505+
15021506
def __getattr__(self, name):
15031507
return getattr(self.method_pb, name)
15041508

@@ -1836,13 +1840,16 @@ def ident(self) -> metadata.Address:
18361840

18371841
@utils.cached_property
18381842
def paged_result_field(self) -> Optional[Field]:
1839-
"""Return the response pagination field if the method is paginated."""
1840-
# If the request field lacks any of the expected pagination fields,
1841-
# then the method is not paginated.
1843+
"""Return the response pagination field if the method is paginated.
1844+
1845+
The request field must have a page_token field and a page_size field (or
1846+
for legacy APIs, a max_results field) and the response field
1847+
must have a next_token_field and a repeated field.
1848+
1849+
For the purposes of supporting legacy APIs, additional wrapper types are
1850+
allowed.
1851+
"""
18421852

1843-
# The request must have page_token and response must have next_page_token fields
1844-
# because those fields keep track of pagination progress.
1845-
18461853
for source, source_type, name in (
18471854
(self.input, str, "page_token"),
18481855
(self.output, str, "next_page_token"),
@@ -1851,35 +1858,29 @@ def paged_result_field(self) -> Optional[Field]:
18511858
if not field or field.type != source_type:
18521859
return None
18531860

1854-
# The request must have max_results or page_size
1861+
# The request must have page_size (or max_results if legacy API)
18551862
page_fields = (
18561863
self.input.fields.get("max_results", None),
18571864
self.input.fields.get("page_size", None),
18581865
)
18591866
page_field_size = next((field for field in page_fields if field), None)
18601867
if not page_field_size:
18611868
return None
1862-
1869+
18631870
# If the field is max_results and uses the UInt32Value and Int32Value wrappers,
18641871
# the package must be in the allowlist.
1865-
wrappers_allowed = ENABLE_WRAPPER_TYPES_FOR_PAGE_SIZE.get(self.input.meta.address.proto_package, False)
1866-
1867-
# ALTERNATIVE:
1868-
# As opposed to using a dictionary with package names as keys and True/False as values, we could
1869-
# Use a set and check to see if the package name is in the list
1870-
# WRAPPERS_ALLOWED_PACKAGE_LIST = {"google.cloud.bigquery.v2"}
1871-
# self.input.meta.address.proto_package in WRAPPERS_ALLOWED_PACKAGE_LIST
1872+
package_name = self.input.meta.address.proto_package
18721873

18731874
if page_field_size.type == int or (
1874-
# The following additional checks are for several members of the BQ family of
1875-
# APIs, which use legacy wrapper types: "UInt32Value" and "Int32Value"}
1875+
# The following additional checks are related to several members of the BQ family of
1876+
# APIs, which use the legacy wrapper types: "UInt32Value" and "Int32Value"}
18761877
# for max_results.
18771878
# NOTE:
18781879
# bigquery_v2 should be paginated
1879-
# but bigquery_connection_v1beta1 should NOT be paginated
1880-
wrappers_allowed
1881-
and isinstance(page_field_size.type, MessageType)
1880+
# but bigquery_connection_v1beta1 should NOT be paginated
1881+
isinstance(page_field_size.type, MessageType)
18821882
and page_field_size.type.message_pb.name in {"UInt32Value", "Int32Value"}
1883+
and package_name in self.PACKAGES_WITH_ALLOWED_WRAPPERS
18831884
):
18841885
pass
18851886
else:

0 commit comments

Comments
 (0)