Skip to content

Commit 73d6c71

Browse files
committed
updates type hinting and formatting
1 parent bf61066 commit 73d6c71

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

google/cloud/bigquery/routine/routine.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
"""Define resources for the BigQuery Routines API."""
18-
18+
import typing
1919
from typing import Any, Dict, Optional, Union
2020

2121
import google.cloud._helpers # type: ignore
@@ -864,13 +864,15 @@ def runtime_connection(self, value: Optional[str]):
864864
@property
865865
def max_batching_rows(self) -> Optional[int]:
866866
"""Optional. Maximum number of rows in each batch sent to the external runtime."""
867-
return _helpers._int_or_none(self._properties.get("maxBatchingRows"))
867+
return typing.cast(
868+
int, _helpers._int_or_none(self._properties.get("maxBatchingRows"))
869+
)
868870

869871
@max_batching_rows.setter
870872
def max_batching_rows(self, value: Optional[int]):
871873
if value is not None and not isinstance(value, int):
872874
raise ValueError("max_batching_rows must be an integer or None.")
873-
self._properties["maxBatchingRows"] = _helpers._str_or_none(value)
875+
self._properties["maxBatchingRows"] = value
874876

875877
@property
876878
def runtime_version(self) -> Optional[str]:

tests/unit/routine/test_external_runtime_options.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def object_under_test(target_class):
3232
def test_ctor(target_class):
3333
container_memory = "1G"
3434
container_cpu = 1
35-
runtime_connection = "projects/my-project/locations/us-central1/connections/my-connection"
35+
runtime_connection = (
36+
"projects/my-project/locations/us-central1/connections/my-connection"
37+
)
3638
max_batching_rows = 100
3739
runtime_version = "python-3.11"
3840

@@ -64,7 +66,9 @@ def test_container_cpu(object_under_test):
6466

6567

6668
def test_runtime_connection(object_under_test):
67-
runtime_connection = "projects/my-project/locations/us-central1/connections/my-connection"
69+
runtime_connection = (
70+
"projects/my-project/locations/us-central1/connections/my-connection"
71+
)
6872
object_under_test.runtime_connection = runtime_connection
6973
assert object_under_test.runtime_connection == runtime_connection
7074

@@ -169,12 +173,16 @@ def test_invalid_container_cpu(object_under_test):
169173

170174

171175
def test_invalid_runtime_connection(object_under_test):
172-
with pytest.raises(ValueError, match="runtime_connection must be a string or None."):
176+
with pytest.raises(
177+
ValueError, match="runtime_connection must be a string or None."
178+
):
173179
object_under_test.runtime_connection = 123
174180

175181

176182
def test_invalid_max_batching_rows(object_under_test):
177-
with pytest.raises(ValueError, match="max_batching_rows must be an integer or None."):
183+
with pytest.raises(
184+
ValueError, match="max_batching_rows must be an integer or None."
185+
):
178186
object_under_test.max_batching_rows = "100"
179187

180188

0 commit comments

Comments
 (0)