`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* ResponseClosed -> StreamClosed * Update docs for StreamClosed
authored by Tom Christie · committed by GitHub · parent 6a99f6f · Browse files · 5 files·+24 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+24 added−25 removed
- tests:+2 added−2 removed
- other:+22 added−23 removed
Provenance
- Commit
9b8f5af- Tree
9548c95- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
6a99f6f
5 files changed+24 added−25 removed
modified:docs/exceptions.md+3 added-3 removed
160 unmodified linesExpand all161162163164165166167168169170171172170171172160 unmodified linesExpand all
::: httpx.StreamConsumed :docstring:
::: httpx.StreamClosed :docstring:
::: httpx.ResponseNotRead :docstring:
::: httpx.RequestNotRead :docstring:
::: httpx.ResponseClosed :docstring:modified:httpx/__init__.py+2 added-2 removed
21 unmodified lines22 ReadTimeout,23 RemoteProtocolError,24 RequestError,25 RequestNotRead,26- ResponseClosed,26 ResponseNotRead,27+ StreamClosed,28 StreamConsumed,29 StreamError,30 TimeoutException,31 TooManyRedirects,66 unmodified lines98 "Request",99 "RequestError",100 "RequestNotRead",101 "Response",102- "ResponseClosed",102 "ResponseNotRead",103 "StatusCode",104 "stream",105+ "StreamClosed",106 "StreamConsumed",107 "StreamError",108 "SyncByteStream",109 "Timeout",15 unmodified linesmodified:httpx/_exceptions.py+14 added-15 removed
25 unmodified lines26 * InvalidURL27 * CookieConflict28 * StreamError29 x StreamConsumed30+ x StreamClosed31 x ResponseNotRead32 x RequestNotRead32- x ResponseClosed33 """34 import contextlib35 import typing36 224 unmodified lines261 # These may occur as the result of a programming error, by accessing262 # the request/response stream in an invalid manner.263 264 265-class StreamError(Exception):265+class StreamError(RuntimeError):266 """267 The base class for stream exceptions.268 269 The developer made an error in accessing the request stream in21 unmodified lines291 )292 super().__init__(message)293 294 295-class ResponseNotRead(StreamError):295+class StreamClosed(StreamError):296 """297- Attempted to access streaming response content, without having called `read()`.297+ Attempted to read or stream response content, but the request has been298+ closed.299 """300 301 def __init__(self) -> None:301- message = "Attempted to access streaming response content, without having called `read()`."302+ message = (303+ "Attempted to read or stream content, but the stream has " "been closed."304+ )305 super().__init__(message)306 307 305-class RequestNotRead(StreamError):308+class ResponseNotRead(StreamError):309 """307- Attempted to access streaming request content, without having called `read()`.310+ Attempted to access streaming response content, without having called `read()`.311 """312 313 def __init__(self) -> None:311- message = "Attempted to access streaming request content, without having called `read()`."314+ message = "Attempted to access streaming response content, without having called `read()`."315 super().__init__(message)316 317 315-class ResponseClosed(StreamError):318+class RequestNotRead(StreamError):319 """317- Attempted to read or stream response content, but the request has been318- closed.320+ Attempted to access streaming request content, without having called `read()`.321 """322 323 def __init__(self) -> None:322- message = (323- "Attempted to read or stream response content, but the request has "324- "been closed."325- )324+ message = "Attempted to access streaming request content, without having called `read()`."325 super().__init__(message)326 327 328 @contextlib.contextmanager11 unmodified linesmodified:httpx/_models.py+3 added-3 removed
25 unmodified lines26 CookieConflict,27 HTTPStatusError,28 InvalidURL,29 RequestNotRead,30- ResponseClosed,30 ResponseNotRead,31+ StreamClosed,32 StreamConsumed,33 request_context,34 )35 from ._status_codes import codes1185 unmodified lines1221 """1222 if self.is_stream_consumed:1223 raise StreamConsumed()1224 if self.is_closed:1225- raise ResponseClosed()1225+ raise StreamClosed()1226 if not isinstance(self.stream, SyncByteStream):1227 raise RuntimeError("Attempted to call a sync iterator on an async stream.")1228 1229 self.is_stream_consumed = True89 unmodified lines1319 """1320 if self.is_stream_consumed:1321 raise StreamConsumed()1322 if self.is_closed:1323- raise ResponseClosed()1323+ raise StreamClosed()1324 if not isinstance(self.stream, AsyncByteStream):1325 raise RuntimeError("Attempted to call an async iterator on an sync stream.")1326 1327 self.is_stream_consumed = True217 unmodified linesmodified:tests/models/test_responses.py+2 added-2 removed
658 unmodified lines659 content=streaming_body(),660 )661 662 response.close()663- with pytest.raises(httpx.ResponseClosed):663+ with pytest.raises(httpx.StreamClosed):664 response.read()665 666 667 @pytest.mark.asyncio3 unmodified lines671 content=async_streaming_body(),672 )673 674 await response.aclose()675- with pytest.raises(httpx.ResponseClosed):675+ with pytest.raises(httpx.StreamClosed):676 await response.aread()677 678 679 @pytest.mark.asyncio176 unmodified lines