-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: set NotRequired
on all fields that aren't required
#460
Comments
I agree with this. The problem is that the spec is ambiguous because not required is interpreted as None sometimes. I've completely redo the typing on the uvicorn.typing module. |
Also, I don't like the typing module lives on the asgiref package. |
Yeah it's not great that asgi-types is separate and have deviated from the ones in this package. And yeah the spec should probably avoid the term "Optional" for non-required fields when that usually means |
Generally, if the spec says a field is optional, the intent there is that its key can be missing (i.e. it is NotRequired). Happy to take a PR to fix these up. |
There was actually a previous discussion about this when the typing module was introduced by Phil. FYI |
This is more up-to-date: https://github.com/encode/uvicorn/blob/master/uvicorn/_types.py |
sooo, any reason not to copy these upstream? Would be nice if projects like uvicorn or hypercorn could import the types from asgi-types and ensure those are kept up to date instead of keeping slightly different copies in their own repositories |
Time... @jakkdl I've invited you as a collaborator to |
Reading through the spec and
asgiref/typing.py
I noticed thatNotRequired
was used for a few fields, but far from all fields that aren't required. It seems thatstate
got marked asNotRequired
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:
But it clearly ""should"", given that https://asgi.readthedocs.io/en/latest/specs/www.html#request-receive-event says
content
andmore_body
are optional keys. But the types doesn't reflect that, leading to an errorasgiref/asgiref/typing.py
Lines 110 to 113 in db3ff43
The text was updated successfully, but these errors were encountered: