Skip to content

Commit 6558aeb

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
chore(client): validate that max_retries is not None (#337)
1 parent 0966b75 commit 6558aeb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/finch/_base_client.py

+5
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ def __init__(
361361
self._strict_response_validation = _strict_response_validation
362362
self._idempotency_header = None
363363

364+
if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
365+
raise TypeError(
366+
"max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `finch-api.DEFAULT_MAX_RETRIES`"
367+
)
368+
364369
def _enforce_trailing_slash(self, url: URL) -> URL:
365370
if url.raw_path.endswith(b"/"):
366371
return url

tests/test_client.py

+22
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,17 @@ class Model(BaseModel):
875875

876876
assert isinstance(exc.value.__cause__, ValidationError)
877877

878+
def test_client_max_retries_validation(self) -> None:
879+
with pytest.raises(TypeError, match=r"max_retries cannot be None"):
880+
Finch(
881+
base_url=base_url,
882+
access_token=access_token,
883+
client_id=client_id,
884+
client_secret=client_secret,
885+
_strict_response_validation=True,
886+
max_retries=cast(Any, None),
887+
)
888+
878889
@pytest.mark.respx(base_url=base_url)
879890
def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None:
880891
class Model(BaseModel):
@@ -1782,6 +1793,17 @@ class Model(BaseModel):
17821793

17831794
assert isinstance(exc.value.__cause__, ValidationError)
17841795

1796+
async def test_client_max_retries_validation(self) -> None:
1797+
with pytest.raises(TypeError, match=r"max_retries cannot be None"):
1798+
AsyncFinch(
1799+
base_url=base_url,
1800+
access_token=access_token,
1801+
client_id=client_id,
1802+
client_secret=client_secret,
1803+
_strict_response_validation=True,
1804+
max_retries=cast(Any, None),
1805+
)
1806+
17851807
@pytest.mark.respx(base_url=base_url)
17861808
@pytest.mark.asyncio
17871809
async def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None:

0 commit comments

Comments
 (0)