Skip to content

Commit 7e3c00f

Browse files
committed
Avoid timeout match suppressions
1 parent 8cf510f commit 7e3c00f

4 files changed

Lines changed: 52 additions & 12 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ log_cli = true
333333
[tool.coverage]
334334
run.branch = true
335335
report.exclude_also = [
336-
"case _ as unreachable:\n\\s*assert_never\\(",
337336
"if TYPE_CHECKING:",
338337
]
339338
report.show_missing = true

spelling_private_dict.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ plugins
7979
png
8080
pragma
8181
py
82-
pyrefly
8382
pyright
8483
pytest
8584
readme
@@ -98,7 +97,6 @@ todo
9897
traceback
9998
travis
10099
txt
101-
ty
102100
unmocked
103101
untyped
104102
url

src/vws/transports.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""HTTP transport implementations for VWS clients."""
22

33
from collections.abc import Awaitable
4-
from typing import Protocol, Self, assert_never, runtime_checkable
4+
from typing import Protocol, Self, runtime_checkable
55

66
import httpx
77
import requests
@@ -150,22 +150,21 @@ def __call__(
150150
A Response populated from the httpx response.
151151
"""
152152
match request_timeout:
153-
case (connect_timeout, read_timeout):
153+
case tuple() as timeout:
154+
connect_timeout, read_timeout = timeout
154155
httpx_timeout = httpx.Timeout(
155156
connect=connect_timeout,
156157
read=read_timeout,
157158
write=None,
158159
pool=None,
159160
)
160-
case float() | int() as timeout:
161+
case timeout:
161162
httpx_timeout = httpx.Timeout(
162163
connect=timeout,
163164
read=timeout,
164165
write=None,
165166
pool=None,
166167
)
167-
case _ as unreachable:
168-
assert_never(unreachable) # pyrefly: ignore[bad-argument-type] # ty: ignore[type-assertion-failure]
169168

170169
httpx_response = self._client.request(
171170
method=method,
@@ -275,22 +274,21 @@ async def __call__(
275274
A Response populated from the httpx response.
276275
"""
277276
match request_timeout:
278-
case (connect_timeout, read_timeout):
277+
case tuple() as timeout:
278+
connect_timeout, read_timeout = timeout
279279
httpx_timeout = httpx.Timeout(
280280
connect=connect_timeout,
281281
read=read_timeout,
282282
write=None,
283283
pool=None,
284284
)
285-
case float() | int() as timeout:
285+
case timeout:
286286
httpx_timeout = httpx.Timeout(
287287
connect=timeout,
288288
read=timeout,
289289
write=None,
290290
pool=None,
291291
)
292-
case _ as unreachable:
293-
assert_never(unreachable) # pyrefly: ignore[bad-argument-type] # ty: ignore[type-assertion-failure]
294292

295293
httpx_response = await self._client.request(
296294
method=method,

tests/test_transports.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ def test_tuple_timeout() -> None:
6161
assert isinstance(response, Response)
6262
assert response.status_code == HTTPStatus.OK
6363

64+
@staticmethod
65+
@respx.mock
66+
def test_int_timeout() -> None:
67+
"""``HTTPXTransport`` works with an int timeout."""
68+
route = respx.post(url="https://example.com/test").mock(
69+
return_value=httpx.Response(
70+
status_code=HTTPStatus.OK,
71+
text="OK",
72+
),
73+
)
74+
transport = HTTPXTransport()
75+
response = transport(
76+
method="POST",
77+
url="https://example.com/test",
78+
headers={"Content-Type": "text/plain"},
79+
data=b"hello",
80+
request_timeout=30,
81+
)
82+
assert route.called
83+
assert isinstance(response, Response)
84+
assert response.status_code == HTTPStatus.OK
85+
6486
@staticmethod
6587
@respx.mock
6688
def test_context_manager() -> None:
@@ -137,6 +159,29 @@ async def test_tuple_timeout() -> None:
137159
assert isinstance(response, Response)
138160
assert response.status_code == HTTPStatus.OK
139161

162+
@staticmethod
163+
@pytest.mark.asyncio
164+
@respx.mock
165+
async def test_int_timeout() -> None:
166+
"""``AsyncHTTPXTransport`` works with an int timeout."""
167+
route = respx.post(url="https://example.com/test").mock(
168+
return_value=httpx.Response(
169+
status_code=HTTPStatus.OK,
170+
text="OK",
171+
),
172+
)
173+
transport = AsyncHTTPXTransport()
174+
response = await transport(
175+
method="POST",
176+
url="https://example.com/test",
177+
headers={"Content-Type": "text/plain"},
178+
data=b"hello",
179+
request_timeout=30,
180+
)
181+
assert route.called
182+
assert isinstance(response, Response)
183+
assert response.status_code == HTTPStatus.OK
184+
140185
@staticmethod
141186
@pytest.mark.asyncio
142187
@respx.mock

0 commit comments

Comments
 (0)