Accept any sequence of header pairs, not just list - #204
Conversation
Callers shouldn't have to copy a tuple or h11 headers object into a list.
|
CI is green on tests; the remaining mark is |
Tuple-backed header sequences exercise the list() conversions added when Headers widened beyond list.
|
Pushed Sequence-backed header tests (tuple as well as list) for the |
| subprotocol = None | ||
| upgrade = b"" | ||
| headers: Headers = [] | ||
| headers: list[tuple[bytes, bytes]] = [] |
There was a problem hiding this comment.
Why can't it be the newly defined Headers type with a sequence here and in the similar code changes?
There was a problem hiding this comment.
Those two locals are accumulators. We .append header pairs while walking h11's event. Headers is Sequence[tuple[bytes, bytes]], and mypy --strict then reports Sequence[...] has no attribute "append" on those two calls (lines 229 and 420).
Incoming values and extra_headers already use Headers. The handshake still builds a list, then stores it on Request.extra_headers.
We only iterate header pairs. Typing them as
listmeant a tuple orh11.Headersneeded a pointlesslist(...)copy.Fixes #173