File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -779,6 +779,11 @@ def __init__(
779
779
else :
780
780
timeout = DEFAULT_TIMEOUT
781
781
782
+ if http_client is not None and not isinstance (http_client , httpx .Client ): # pyright: ignore[reportUnnecessaryIsInstance]
783
+ raise TypeError (
784
+ f"Invalid `http_client` argument; Expected an instance of `httpx.Client` but got { type (http_client )} "
785
+ )
786
+
782
787
super ().__init__ (
783
788
version = version ,
784
789
limits = limits ,
@@ -1308,6 +1313,11 @@ def __init__(
1308
1313
else :
1309
1314
timeout = DEFAULT_TIMEOUT
1310
1315
1316
+ if http_client is not None and not isinstance (http_client , httpx .AsyncClient ): # pyright: ignore[reportUnnecessaryIsInstance]
1317
+ raise TypeError (
1318
+ f"Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got { type (http_client )} "
1319
+ )
1320
+
1311
1321
super ().__init__ (
1312
1322
version = version ,
1313
1323
base_url = base_url ,
Original file line number Diff line number Diff line change @@ -328,6 +328,17 @@ def test_http_client_timeout_option(self) -> None:
328
328
timeout = httpx .Timeout (** request .extensions ["timeout" ]) # type: ignore
329
329
assert timeout == DEFAULT_TIMEOUT # our default
330
330
331
+ async def test_invalid_http_client (self ) -> None :
332
+ with pytest .raises (TypeError , match = "Invalid `http_client` arg" ):
333
+ async with httpx .AsyncClient () as http_client :
334
+ Cloudflare (
335
+ base_url = base_url ,
336
+ api_key = api_key ,
337
+ api_email = api_email ,
338
+ _strict_response_validation = True ,
339
+ http_client = cast (Any , http_client ),
340
+ )
341
+
331
342
def test_default_headers_option (self ) -> None :
332
343
client = Cloudflare (
333
344
base_url = base_url ,
@@ -1075,6 +1086,17 @@ async def test_http_client_timeout_option(self) -> None:
1075
1086
timeout = httpx .Timeout (** request .extensions ["timeout" ]) # type: ignore
1076
1087
assert timeout == DEFAULT_TIMEOUT # our default
1077
1088
1089
+ def test_invalid_http_client (self ) -> None :
1090
+ with pytest .raises (TypeError , match = "Invalid `http_client` arg" ):
1091
+ with httpx .Client () as http_client :
1092
+ AsyncCloudflare (
1093
+ base_url = base_url ,
1094
+ api_key = api_key ,
1095
+ api_email = api_email ,
1096
+ _strict_response_validation = True ,
1097
+ http_client = cast (Any , http_client ),
1098
+ )
1099
+
1078
1100
def test_default_headers_option (self ) -> None :
1079
1101
client = AsyncCloudflare (
1080
1102
base_url = base_url ,
You can’t perform that action at this time.
0 commit comments