-
-
Notifications
You must be signed in to change notification settings - Fork 857
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
Exception hierarchy #1095
Exception hierarchy #1095
Conversation
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.
Wonderful ✨
The split between "request errors" vs "developer errors" is a real improvement over other HTTP clients (eg Requests crams everything into RequestError
, so genuine developer errors typically unnoticed due to catch-all except requests.RequestError
).
@@ -44,7 +50,8 @@ class DeflateDecoder(Decoder): | |||
See: https://stackoverflow.com/questions/1838699 | |||
""" | |||
|
|||
def __init__(self) -> None: | |||
def __init__(self, request: "Request") -> None: | |||
self.request = request |
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.
? (Applicable to all other decoders here)
self.request = request | |
super().__init__(request) |
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.
Yeah a guess a lot of other Python developers would tend always just rely on "hey I'm supposed to call super
right". Personally, I think explicit is preferable to indirect here. Calling into super
isn't always necessary or inherently the "right" thing to do.
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 see, well then I guess Decoder
would really be better served by a Protocol
, rather than a full-fledged base class… But we only have them on Py38+, which is unfortunate.
class Decoder(Protocol):
request: Request
def decode(self, data: bytes) -> bytes:
...
def flush(self) -> bytes:
...
But maybe we could then also use the request: Request
annotation on the Decoder
interface, remove its constructor, and add an explicit constructor for IdentityDecoder
(for consistency with other decoder classes)?
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.
MultiDecoder
inherits the Decoder
interface, but do not have this property
From my point of view, MultiDecoder
, TextDecoder
and LineDecoder
should be renamed, since they:
- on one hand these Decoders imitates the real decoders (having
decode
andflush
) - on the other hand these decoders violates Liskov's substitution principle (I don't want to be so nerd,
mypy
pointed it for me), e.g. as they accept different types as args of decode
Co-authored-by: Florimond Manca <[email protected]>
Co-authored-by: Florimond Manca <[email protected]>
Co-authored-by: Florimond Manca <[email protected]>
Co-authored-by: Florimond Manca <[email protected]>
Refs #949
HTTPError
, in favour of an actually meaningfulRequestError
.RedirectError
which encompassed two totally different kinds of error (one a coding error, the other a request error), and introducingTransportError
.__init__
parameters on all exceptions..request
· ConnectTimeout
· ReadTimeout
· WriteTimeout
· PoolTimeout
· ConnectError
· ReadError
· WriteError
· CloseError
.request
,.response