Skip to content

Commit 8bdcd53

Browse files
Reflexcursoragent
andcommitted
chore: fix pyright on H2 bulkhead integration test
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 76a9ecb commit 8bdcd53

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

tests/test_h2_bulkhead_integration.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import tempfile
1616
import threading
1717
import subprocess
18-
from typing import Any, Iterator
18+
from typing import Any, Iterator, cast
1919
from pathlib import Path
2020

2121
import httpx
@@ -26,9 +26,11 @@
2626
import h2.events # noqa: E402
2727
import h2.settings # noqa: E402
2828
import h2.connection # noqa: E402
29+
import h2.exceptions # noqa: E402
2930

3031
import runloop_api_client._base_client as _base_mod
3132
from runloop_api_client import AsyncRunloop
33+
from runloop_api_client._base_client import make_request_options
3234

3335
pytestmark = pytest.mark.timeout(30)
3436

@@ -53,7 +55,7 @@ def _clear_pool_state() -> None:
5355

5456

5557
@pytest.fixture(autouse=True)
56-
def _reset_pools() -> Iterator[None]:
58+
def _reset_pools() -> Iterator[None]: # pyright: ignore[reportUnusedFunction]
5759
_clear_pool_state()
5860
yield
5961
_clear_pool_state()
@@ -221,8 +223,10 @@ async def respond(stream_id: int, st: dict[str, Any]) -> None:
221223
events = conn.receive_data(data)
222224
except h2.exceptions.ProtocolError:
223225
break
224-
for event in events:
225-
if isinstance(event, h2.events.RequestReceived):
226+
for raw_event in events:
227+
# h2's Event hierarchy is poorly typed under pyright strict.
228+
event = cast(Any, raw_event)
229+
if isinstance(raw_event, h2.events.RequestReceived):
226230
st = streams.setdefault(
227231
event.stream_id,
228232
{
@@ -250,19 +254,19 @@ async def respond(stream_id: int, st: dict[str, Any]) -> None:
250254
self.active_waits += 1
251255
if str(st["path"]).endswith("/upload_file"):
252256
self.active_uploads += 1
253-
elif isinstance(event, h2.events.DataReceived):
257+
elif isinstance(raw_event, h2.events.DataReceived):
254258
st = streams.setdefault(event.stream_id, {"body": bytearray(), "flow_controlled": 0})
255259
st["body"].extend(event.data)
256260
stall_upload = self.upload_stall_s > 0 and str(st.get("path", "")).endswith("/upload_file")
257261
if stall_upload and not self.release_upload_credit.is_set():
258262
st["flow_controlled"] = st.get("flow_controlled", 0) + event.flow_controlled_length
259263
else:
260264
conn.acknowledge_received_data(event.flow_controlled_length, event.stream_id)
261-
elif isinstance(event, h2.events.StreamEnded):
265+
elif isinstance(raw_event, h2.events.StreamEnded):
262266
st = streams.get(event.stream_id)
263267
if st is not None:
264268
asyncio.create_task(respond(event.stream_id, st))
265-
elif isinstance(event, h2.events.StreamReset):
269+
elif isinstance(raw_event, h2.events.StreamReset):
266270
streams.pop(event.stream_id, None)
267271
async with write_lock:
268272
to_send = conn.data_to_send()
@@ -318,7 +322,7 @@ async def wait_call() -> object:
318322
return await client.post(
319323
"/v1/devboxes/dbx_shared/wait_for_status",
320324
body={"statuses": ["running"], "timeout_seconds": 5},
321-
options={"extra_headers": wait_headers},
325+
options=make_request_options(extra_headers=wait_headers),
322326
cast_to=object,
323327
)
324328

@@ -381,7 +385,9 @@ async def upload() -> object:
381385
"/v1/devboxes/dbx_up/upload_file",
382386
content=payload,
383387
cast_to=object,
384-
options={"extra_headers": {"content-type": "application/octet-stream"}},
388+
options=make_request_options(
389+
extra_headers={"content-type": "application/octet-stream"},
390+
),
385391
)
386392

387393
upload_task = asyncio.create_task(upload())

0 commit comments

Comments
 (0)