diff --git a/CHANGES/6916.bugfix b/CHANGES/6916.bugfix new file mode 100644 index 00000000000..4c4329c1abe --- /dev/null +++ b/CHANGES/6916.bugfix @@ -0,0 +1 @@ +Add __repr__ to EmptyStreamReader to avoid AttributeErrors. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index bda74215d50..6917f882f49 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -160,6 +160,7 @@ Jake Davis Jakob Ackermann Jakub Wilk Jan Buchar +Jarno Elonen Jashandeep Sohi Jean-Baptiste Estival Jens Steinhauser diff --git a/aiohttp/streams.py b/aiohttp/streams.py index 6d840bdc0c8..60e40fb2576 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -492,6 +492,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 diff --git a/tests/test_streams.py b/tests/test_streams.py index 92fcf6be99e..f305ed56e77 100644 --- a/tests/test_streams.py +++ b/tests/test_streams.py @@ -1062,6 +1062,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