Skip to content

Commit

Permalink
Applied suggestion: Use correct type hints for attributes of `Incompl…
Browse files Browse the repository at this point in the history
…eteRead`
  • Loading branch information
crazyscientist committed Feb 5, 2024
1 parent b2c25a9 commit 12ce2a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/urllib3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ class IncompleteRead(HTTPError, httplib_IncompleteRead):
"""

def __init__(self, partial: int, expected: int) -> None:
self.partial = partial # type: ignore[assignment]
self.expected = expected
self.partial: int = partial # type: ignore[assignment]
self.expected: int = expected

def __repr__(self) -> str:
return "IncompleteRead(%i bytes read, %i more expected)" % (
self.partial, # type: ignore[str-format]
self.partial,
self.expected,
)

Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def _error_catcher(self) -> typing.Generator[None, None, None]:
if (
e.expected is not None
and e.partial is not None
and int(e.expected) == -int(e.partial)
and e.expected == -e.partial
):
arg = "Protocol violation: Response may not contain content."
else:
Expand Down
2 changes: 1 addition & 1 deletion test/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ def test_buggy_incomplete_read(self) -> None:

orig_ex = ctx.value.args[1]
assert isinstance(orig_ex, IncompleteRead)
assert orig_ex.partial == 0 # type: ignore[comparison-overlap]
assert orig_ex.partial == 0
assert orig_ex.expected == content_length

def test_incomplete_chunk(self) -> None:
Expand Down

0 comments on commit 12ce2a7

Please sign in to comment.