Description
Reading through the spec and asgiref/typing.py
I noticed that NotRequired
was used for a few fields, but far from all fields that aren't required. It seems that state
got marked as NotRequired
in #354 for backwards compatibility reasons, but I don't see why the marker shouldn't also be used for all fields that are mentioned as ""Optional"" in the spec.
This arose as I was working on hypercorn, which bundles a copy of the typing spec, where the equivalent of this failed to typecheck:
from asgiref.typing import HTTPRequestEvent
e: HTTPRequestEvent = {"type": "http.request"}
But it clearly ""should"", given that https://asgi.readthedocs.io/en/latest/specs/www.html#request-receive-event says content
and more_body
are optional keys. But the types doesn't reflect that, leading to an error
Lines 110 to 113 in db3ff43