-
Notifications
You must be signed in to change notification settings - Fork 42
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
Fix compatibility with httpx 0.28.0 #278
base: master
Are you sure you want to change the base?
Conversation
method = ( | ||
request.method.decode("ascii").upper() | ||
if isinstance(request.method, bytes) | ||
else request.method.upper() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note that the new httpx code still uppercases the method, so that's redundant here. I'd just decode from bytes:
method = ( | |
request.method.decode("ascii").upper() | |
if isinstance(request.method, bytes) | |
else request.method.upper() | |
) | |
method = ( | |
request.method.decode("ascii") | |
if isinstance(request.method, bytes) | |
else request.method | |
) |
request.method.decode("ascii").upper() | ||
if isinstance(request.method, bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should a DeprecationWarning
be raised for bytes so that codebases can be updated and this support can eventually be dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'd expect respx to follow the same argument conventions as httpx, and the project shouldn't try and maintain accepting bytes here if httpx has dropped support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the minimum HTTPX version also be bumped to match?
Line 44 in 366dd0b
install_requires=["httpx>=0.21.0"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested as ndhansen#1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the minimum HTTPX version also be bumped to match?
I don’t think so, the library should still be compatible with older versions of httpx (they used to accept bytes for the method
kwarg).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bytes come from httpcore, and we’re only getting bytes because we’re hooking the mock after httpcore
issued the request. So there’s nothing users can do about this warning.
Commit that changes |
Prior to httpx version
0.28.0
, request methods were implicitly converted from bytes to strings. In version0.28.0
that is no longer the case.Since httpx request objects expect strings for the method field, and httpcore request objects enforce bytes, I've copied the conversion from bytes to strings from the previous httpx version in to respx.
I didn't add tests because there are no explicit tests on the
to_httpx_request
method, but I can if you'd like.Fixes #277.