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 23ea188a074..7c633b30169 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -155,6 +155,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 d5f4c2baaf8..32ec7f148f6 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -502,6 +502,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 a16f7ebf4ad..29eab256578 100644 --- a/tests/test_streams.py +++ b/tests/test_streams.py @@ -1132,6 +1132,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