From 2ca3c3861681dd2aa3bcce42c554f74cc03e213a Mon Sep 17 00:00:00 2001 From: Adam Bannister Date: Sat, 9 Nov 2019 14:20:18 +0100 Subject: [PATCH] switch noop from function to class (#4322) --- CHANGES/4282.bugfix | 1 + aiohttp/helpers.py | 9 ++++----- tests/test_web_protocol.py | 15 --------------- 3 files changed, 5 insertions(+), 20 deletions(-) create mode 100644 CHANGES/4282.bugfix diff --git a/CHANGES/4282.bugfix b/CHANGES/4282.bugfix new file mode 100644 index 00000000000..27062bb91bb --- /dev/null +++ b/CHANGES/4282.bugfix @@ -0,0 +1 @@ +Remove warning messages from noop. diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index cb350e80877..0b17d1271f1 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -24,6 +24,7 @@ Awaitable, Callable, Dict, + Generator, Iterable, Iterator, List, @@ -100,12 +101,10 @@ def all_tasks( coroutines = asyncio.coroutines old_debug = coroutines._DEBUG # type: ignore -# prevent "coroutine noop was never awaited" warning. -coroutines._DEBUG = False # type: ignore - -async def noop(*args: Any, **kwargs: Any) -> None: - return +class noop: + def __await__(self) -> Generator[None, None, None]: + yield coroutines._DEBUG = old_debug # type: ignore diff --git a/tests/test_web_protocol.py b/tests/test_web_protocol.py index 3cc7c20b4de..c578f7c3cb8 100644 --- a/tests/test_web_protocol.py +++ b/tests/test_web_protocol.py @@ -255,21 +255,6 @@ async def test_bad_method(srv, buf) -> None: assert buf.startswith(b'HTTP/1.0 400 Bad Request\r\n') -async def test_data_received_error(srv, buf) -> None: - transport = srv.transport - srv._request_parser = mock.Mock() - srv._request_parser.feed_data.side_effect = TypeError - - srv.data_received( - b'!@#$ / HTTP/1.0\r\n' - b'Host: example.com\r\n\r\n') - - await asyncio.sleep(0) - assert buf.startswith(b'HTTP/1.0 500 Internal Server Error\r\n') - assert transport.close.called - assert srv._error_handler is None - - async def test_line_too_long(srv, buf) -> None: srv.data_received(b''.join([b'a' for _ in range(10000)]) + b'\r\n\r\n')