Skip to content
Myr

Improve type hinting for `HTTPError.request` (#886)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Florimond Manca · committed by GitHub · parent d63108d · Browse files · 2 files+13 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−6 removed

  • other:+13 added−6 removed

2 files+13 added−6 removed

modified:httpx/_client.py+4 added-4 removed
678 unmodified lines
679 except HTTPError as exc:680 # Add the original request to any HTTPError unless681 # there'a already a request attached in the case of682 # a ProxyError.683 if exc.request is None:684 exc.request = request683 if exc._request is None:684 exc._request = request685 raise686687 self.cookies.extract_cookies(response)688
508 unmodified lines
1197 except HTTPError as exc:1198 # Add the original request to any HTTPError unless1199 # there'a already a request attached in the case of1200 # a ProxyError.1201 if exc.request is None:1202 exc.request = request1201 if exc._request is None:1202 exc._request = request1203 raise12041205 self.cookies.extract_cookies(response)1206
256 unmodified lines
modified:httpx/_exceptions.py+9 added-2 removed
10 unmodified lines
1112 def __init__(13 self, *args: typing.Any, request: "Request" = None, response: "Response" = None14 ) -> None:15 self.response = response16 self.request = request or getattr(self.response, "request", None)15 super().__init__(*args)16 self._request = request or (response.request if response is not None else None)17 self.response = response1819 @property20 def request(self) -> "Request":21 # NOTE: this property exists so that a `Request` is exposed to type22 # checkers, instead of `Optional[Request]`.23 assert self._request is not None # Populated by the client.24 return self._request252627# Timeout exceptions...282930class TimeoutException(HTTPError):
145 unmodified lines