Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ def _get_chunk_left(self):
return chunk_left

def _read_chunked(self, amt=None):
assert self.chunked != _UNKNOWN
if self.chunked == _UNKNOWN:
raise IncompleteRead("Unkown chunk detected.")

value = []
try:
while True:
Expand All @@ -594,7 +596,8 @@ def _read_chunked(self, amt=None):
raise IncompleteRead(b''.join(value))

def _readinto_chunked(self, b):
assert self.chunked != _UNKNOWN
if self.chunked == _UNKNOWN:
raise IncompleteRead("Unkown chunk detected.")
total_bytes = 0
mvb = memoryview(b)
try:
Expand Down Expand Up @@ -1363,7 +1366,8 @@ def getresponse(self):
except ConnectionError:
self.close()
raise
assert response.will_close != _UNKNOWN
if response.will_close == _UNKNOWN:
raise ConnectionError("Unknown if response will close.")
self.__state = _CS_IDLE

if response.will_close:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `asserts` on HTTPResponse and HTTPConnection with `if...raises` so that the conditional checks work while running with the optimization flag switched on

@Fidget-Spinner Fidget-Spinner Oct 17, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reST requires two backticks for code, not one like markdown :).

Suggested change
Replace `asserts` on HTTPResponse and HTTPConnection with `if...raises` so that the conditional checks work while running with the optimization flag switched on
Replace ``assert`` in :class:`http.client.HTTPResponse` and :class:`http.client.HTTPConnection` with ``raise``
so that conditional checks work while running with Python's runtime optimization
``-O`` flag enabled.