Skip to content

Commit

Permalink
Fix typing errors in examples, check with mypy
Browse files Browse the repository at this point in the history
The examples we provide should also have correct type hints.
  • Loading branch information
jlaine committed Jul 6, 2024
1 parent 7ad382f commit e189d29
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: |
ruff check .
ruff format --check --diff .
mypy src tests
mypy examples src tests
check-manifest
codespell:
Expand Down
4 changes: 2 additions & 2 deletions examples/doq_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@


class DnsClientProtocol(QuicConnectionProtocol):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._ack_waiter: Optional[asyncio.Future[DNSRecord]] = None

async def query(self, query_name: str, query_type: str) -> None:
async def query(self, query_name: str, query_type: str) -> DNSRecord:
# serialize query
query = DNSRecord(
header=DNSHeader(id=0),
Expand Down
7 changes: 5 additions & 2 deletions examples/http3_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ class WebTransportHandler:
def __init__(
self,
*,
connection: HttpConnection,
connection: H3Connection,
scope: Dict,
stream_id: int,
transmit: Callable[[], None],
) -> None:
self.accepted = False
self.closed = False
self.connection = connection
self.http_event_queue: Deque[DataReceived] = deque()
self.http_event_queue: Deque[H3Event] = deque()
self.queue: asyncio.Queue[Dict] = asyncio.Queue()
self.scope = scope
self.stream_id = stream_id
Expand Down Expand Up @@ -387,6 +387,9 @@ def http_event_received(self, event: H3Event) -> None:
transmit=self.transmit,
)
elif method == "CONNECT" and protocol == "webtransport":
assert isinstance(
self._http, H3Connection
), "WebTransport is only supported over HTTP/3"
scope = {
"client": client,
"headers": headers,
Expand Down
2 changes: 1 addition & 1 deletion examples/httpx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def __aiter__(self) -> AsyncIterator[bytes]:


class H3Transport(QuicConnectionProtocol, httpx.AsyncBaseTransport):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

self._http = H3Connection(self._quic)
Expand Down
2 changes: 1 addition & 1 deletion examples/siduck_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class SiduckClient(QuicConnectionProtocol):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._ack_waiter: Optional[asyncio.Future[None]] = None

Expand Down

0 comments on commit e189d29

Please sign in to comment.