diff --git a/README.md b/README.md index 681b87a7e15..6066af741ab 100644 --- a/README.md +++ b/README.md @@ -332,12 +332,12 @@ response = client.post( print(response.headers.get("x-foo")) ``` -#### Undocumented params +#### Undocumented request params If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request options. -#### Undocumented properties +#### Undocumented response properties To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You can also get all the extra fields on the Pydantic model as a dict with diff --git a/src/cloudflare/_base_client.py b/src/cloudflare/_base_client.py index df68237a10f..21c336d5fe8 100644 --- a/src/cloudflare/_base_client.py +++ b/src/cloudflare/_base_client.py @@ -360,6 +360,11 @@ def __init__( self._strict_response_validation = _strict_response_validation self._idempotency_header = None + if max_retries is None: # pyright: ignore[reportUnnecessaryComparison] + raise TypeError( + "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 `cloudflare.DEFAULT_MAX_RETRIES`" + ) + def _enforce_trailing_slash(self, url: URL) -> URL: if url.raw_path.endswith(b"/"): return url diff --git a/tests/test_client.py b/tests/test_client.py index d2bb96ba3ed..9b15628f2bd 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -727,6 +727,16 @@ class Model(BaseModel): assert isinstance(exc.value.__cause__, ValidationError) + def test_client_max_retries_validation(self) -> None: + with pytest.raises(TypeError, match=r"max_retries cannot be None"): + Cloudflare( + base_url=base_url, + api_key=api_key, + api_email=api_email, + _strict_response_validation=True, + max_retries=cast(Any, None), + ) + @pytest.mark.respx(base_url=base_url) def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None: class Model(BaseModel): @@ -1493,6 +1503,16 @@ class Model(BaseModel): assert isinstance(exc.value.__cause__, ValidationError) + async def test_client_max_retries_validation(self) -> None: + with pytest.raises(TypeError, match=r"max_retries cannot be None"): + AsyncCloudflare( + base_url=base_url, + api_key=api_key, + api_email=api_email, + _strict_response_validation=True, + max_retries=cast(Any, None), + ) + @pytest.mark.respx(base_url=base_url) @pytest.mark.asyncio async def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None: