Skip to content

Commit 186d0e9

Browse files
committed
fix(loadtest): use cast() to satisfy both pyright and mypy
1 parent dd5db46 commit 186d0e9

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

loadtest/h2_single_conn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import os
77
import time
8+
from typing import cast
89

910
import httpx
1011

@@ -49,7 +50,7 @@ async def main() -> None:
4950

5051
await client.aclose()
5152

52-
lats = sorted(r["latency_ms"] for r in results) # type: ignore[arg-type]
53+
lats: list[float] = sorted(cast(float, r["latency_ms"]) for r in results)
5354
print(f"{count} requests in {wall_ms:.0f}ms ({count / (wall_ms / 1000):.1f} req/s)")
5455
print(
5556
f"Latency: min={lats[0]:.0f}ms p50={lats[count // 2]:.0f}ms max={lats[-1]:.0f}ms"

loadtest/h2_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import math
77
import os
88
import time
9+
from typing import cast
910

1011
import httpx
1112

@@ -82,10 +83,10 @@ async def wrapped(idx: int) -> dict[str, object]:
8283
for c in clients:
8384
await c.aclose()
8485

85-
latencies: list[float] = sorted(r["latency_ms"] for r in results) # type: ignore[arg-type]
86+
latencies: list[float] = sorted(cast(float, r["latency_ms"]) for r in results)
8687
status_counts: dict[int, int] = {}
8788
for r in results:
88-
s = int(r["status"]) # type: ignore[arg-type]
89+
s = cast(int, r["status"])
8990
status_counts[s] = status_counts.get(s, 0) + 1
9091

9192
print(f"\n=== HTTP/2 Results ===")

loadtest/raw_fetch_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import math
77
import os
88
import time
9+
from typing import cast
910

1011
import httpx
1112

@@ -71,7 +72,7 @@ async def send_one() -> dict[str, object]:
7172

7273
await client.aclose()
7374

74-
latencies: list[float] = sorted(r["latency_ms"] for r in results) # type: ignore[arg-type]
75+
latencies: list[float] = sorted(cast(float, r["latency_ms"]) for r in results)
7576
status_counts: dict[str, int] = {}
7677
for r in results:
7778
key = str(r["status"]) if r["status"] is not None else "network_error"

0 commit comments

Comments
 (0)