Whole file
sendgrid/python-http-client
The author described this change as “fix: add reduce to allow errors to be pickled (#148)”. It counts as a record because the check below fails on the code as it stood at 6d62911ab and passes on dafd02495, with nothing else changed between the two runs.
Projectsendgrid/python-http-client
Fix saved2021-02-10
Sharing licenceMIT · LICENSE
Change size+17 −5
What the code was meant to do, written into the code itself as a save note
fix: add reduce to allow errors to be pickled (#148)
The change
| 4 | 4 | class HTTPError(Exception): | |
| 5 | 5 | """ Base of all other errors""" | |
| 6 | 6 | ||
| 7 | - | def __init__(self, error): | |
| 8 | - | self.status_code = error.code | |
| 9 | - | self.reason = error.reason | |
| 10 | - | self.body = error.read() | |
| 11 | - | self.headers = error.hdrs | |
| 7 | + | def __init__(self, *args): | |
| 8 | + | if len(args) == 4: | |
| 9 | + | self.status_code = args[0] | |
| 10 | + | self.reason = args[1] | |
| 11 | + | self.body = args[2] | |
| 12 | + | self.headers = args[3] | |
| 13 | + | else: | |
| 14 | + | self.status_code = args[0].code | |
| 15 | + | self.reason = args[0].reason | |
| 16 | + | self.body = args[0].read() | |
| 17 | + | self.headers = args[0].hdrs | |
| 18 | + | ||
| 19 | + | def __reduce__(self): | |
| 20 | + | return ( | |
| 21 | + | HTTPError, | |
| 22 | + | (self.status_code, self.reason, self.body, self.headers) | |
| 23 | + | ) | |
| 12 | 24 | ||
| 13 | 25 | @property | |
| 14 | 26 | def to_dict(self): |
The check that tells the two apart
fail→pass·tests/test_unit.py::TestClient::test_pickle_error
Check file tests/test_unit.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it6d62911ab0d0645b499e14bb17c302b48f3c10e4
Broken version dated2021-01-06
Modulepython_http_client.exceptions
Units changedHTTPError
Fingerprintab89ce9b2f782aa3
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.