FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: _determine_timeout problem handling float type timeout by arithmetic1728 · Pull Request #64 · googleapis/python-api-core · GitHub

This repository was archived by the owner on Feb 23, 2026. It is now read-only.
/ python-api-core Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) dotfile  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pip-log.txt
.nox
.cache
.pytest_cache
pytype_output


# Mac
Expand Down Expand Up @@ -57,4 +58,4 @@ system_tests/local_test_setup

# Make sure a generated file isn't accidentally committed.
pylintrc
pylintrc.test
pylintrc.test
14 changes: 8 additions & 6 deletions google/api_core/gapic_v1/method.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def _determine_timeout(default_timeout, specified_timeout, retry):
Returns:
Optional[Timeout]: The timeout to apply to the method or ``None``.
"""
# If timeout is specified as a number instead of a Timeout instance,
# convert it to a ConstantTimeout.
if isinstance(specified_timeout, (int, float)):
specified_timeout = timeout.ConstantTimeout(specified_timeout)
if isinstance(default_timeout, (int, float)):
default_timeout = timeout.ConstantTimeout(default_timeout)

if specified_timeout is DEFAULT:
specified_timeout = default_timeout

Expand All @@ -78,12 +85,7 @@ def _determine_timeout(default_timeout, specified_timeout, retry):
else:
return default_timeout

# If timeout is specified as a number instead of a Timeout instance,
# convert it to a ConstantTimeout.
if isinstance(specified_timeout, (int, float)):
return timeout.ConstantTimeout(specified_timeout)
else:
return specified_timeout
return specified_timeout


class _GapicCallable(object):
Expand Down
24 changes: 23 additions & 1 deletion tests/unit/gapic/test_method.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ def _utcnow_monotonic():
curr_value += delta


def test__determine_timeout():
# Check _determine_timeout always returns a Timeout object.
timeout_type_timeout = timeout.ConstantTimeout(600.0)
returned_timeout = google.api_core.gapic_v1.method._determine_timeout(
600.0, 600.0, None
)
assert isinstance(returned_timeout, timeout.ConstantTimeout)
returned_timeout = google.api_core.gapic_v1.method._determine_timeout(
600.0, timeout_type_timeout, None
)
assert isinstance(returned_timeout, timeout.ConstantTimeout)
returned_timeout = google.api_core.gapic_v1.method._determine_timeout(
timeout_type_timeout, 600.0, None
)
assert isinstance(returned_timeout, timeout.ConstantTimeout)
returned_timeout = google.api_core.gapic_v1.method._determine_timeout(
timeout_type_timeout, timeout_type_timeout, None
)
assert isinstance(returned_timeout, timeout.ConstantTimeout)


def test_wrap_method_basic():
method = mock.Mock(spec=["__call__"], return_value=42)

Expand Down Expand Up @@ -154,7 +175,8 @@ def test_wrap_method_with_default_retry_and_timeout_using_sentinel(unusued_sleep

@mock.patch("time.sleep")
def test_wrap_method_with_overriding_retry_and_timeout(unusued_sleep):
method = mock.Mock(spec=["__call__"], side_effect=[exceptions.NotFound(None), 42])
method = mock.Mock(spec=["__call__"], side_effect=[
exceptions.NotFound(None), 42])
default_retry = retry.Retry()
default_timeout = timeout.ConstantTimeout(60)
wrapped_method = google.api_core.gapic_v1.method.wrap_method(
Expand Down

Back | FazBrowse Home | New Git URL