Skip to content

Commit

Permalink
Add missing __repr__ to streams.EmptyStreamReader (#6916)
Browse files Browse the repository at this point in the history
**EmptyStreamReader** currently inherits `__repr__` from
**StreamReader** , which then tries to access non-existing fields,
causing AttributeErrors. The bug causes issues like this in upstream
code: miguelgrinberg/python-socketio#1032

This PR adds a custom `__repr__` to EmptyStreamReader to fix the
problem.
  • Loading branch information
elonen authored Nov 28, 2022
1 parent 179312e commit abafcda
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/6916.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add __repr__ to EmptyStreamReader to avoid AttributeErrors.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Jake Davis
Jakob Ackermann
Jakub Wilk
Jan Buchar
Jarno Elonen
Jashandeep Sohi
Jean-Baptiste Estival
Jens Steinhauser
Expand Down
3 changes: 3 additions & 0 deletions aiohttp/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ class EmptyStreamReader(StreamReader): # lgtm [py/missing-call-to-init]
def __init__(self) -> None:
pass

def __repr__(self) -> str:
return "<%s>" % self.__class__.__name__

def exception(self) -> Optional[BaseException]:
return None

Expand Down
1 change: 1 addition & 0 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ async def test_unread_empty(self) -> None:

async def test_empty_stream_reader() -> None:
s = streams.EmptyStreamReader()
assert str(s) is not None
assert s.set_exception(ValueError()) is None
assert s.exception() is None
assert s.feed_eof() is None
Expand Down

0 comments on commit abafcda

Please sign in to comment.