Repository navigation
Fix Headers bytes-key lookups and __eq__ with non-iterables (#3898, #3899) - #3900
Open
KaelLee335 wants to merge 2 commits into
Open
KaelLee335 wants to merge 2 commits into
KaelLee335 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3898, fixes #3899.
Two independent
Headersbugs, both inhttpx/_models.py:#3898 — bytes keys cannot be looked up.
HeaderTypesacceptsMapping[bytes, bytes]andHeaders({b"X-Foo": b"bar"})builds fine (keys normalized to'x-foo'), butb"x-foo" in h,h[b"x-foo"]andh.get(b"x-foo")raiseAttributeErrorbecause__getitem__/__delitem__/__contains__callkey.lower().encode()on a bytes key. Fix: use the existing_normalize_header_key()helper, which already handles bothstrandbytes. Inheritedpop()/setdefault()benefit through__getitem__/__delitem__.#3899 —
__eq__raises on non-iterables.Headers() == 123andHeaders() == object()raiseTypeError: 'int' object is not iterablebecause__eq__only caughtValueError. Fix: catch(ValueError, TypeError), matchingdict's convention that==against an unrelated type returnsFalse.Note on scope: this is not a blanket "all bytes APIs work" change.
get_list(bytes)and__setitem__(bytes, ...)still only acceptstr; they are separate pre-existing gaps, not regressions introduced here. LikewiseHeaders == <invalid mapping key>can still raiseAttributeError; those inputs are outside #3899's non-iterable case.Tests
tests/models/test_headers.py: bytes-keyin/getitem/get/del(all four str/bytes case combos, missing-key defaults, duplicate deletion), andHeaders == 123/object()returningFalse.python -m pytest tests/models/test_headers.py -q— 48 passed.