-
-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HttpStatusError and RequestError pickleable
If an error has keyword-only arguments, it needs this extra `__reduce__` method to ensure that unpickling doesn't raise `TypeError: missing (n) required keyword-only argument(s)`
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pickle | ||
|
||
from httpx import HTTPStatusError, RequestError | ||
|
||
|
||
def test_pickle(): | ||
req_err = RequestError("hi!", request=1) | ||
req_err_clone = pickle.loads(pickle.dumps(req_err)) | ||
assert req_err.args == req_err_clone.args | ||
assert req_err.request == req_err_clone.request | ||
|
||
status_err = HTTPStatusError("hi", request="request", response="response") | ||
status_err_clone = pickle.loads(pickle.dumps(status_err)) | ||
assert status_err.args == status_err_clone.args | ||
assert status_err.request == status_err_clone.request | ||
assert status_err.response == status_err_clone.response |