From af53fe00b1a7e09ca1173b56169c40047700fa0e Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 24 May 2018 10:58:25 +0300 Subject: [PATCH] Deprecate custom router (#3021) --- CHANGES/3021.removal | 1 + aiohttp/web_app.py | 3 +++ docs/web_reference.rst | 5 +++++ tests/test_web_app.py | 3 ++- tests/test_web_urldispatcher.py | 3 ++- 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 CHANGES/3021.removal diff --git a/CHANGES/3021.removal b/CHANGES/3021.removal new file mode 100644 index 00000000000..ea54a0f0e3d --- /dev/null +++ b/CHANGES/3021.removal @@ -0,0 +1 @@ +Deprecate custom application's router. \ No newline at end of file diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index a808b06f917..a1a8a817599 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -37,6 +37,9 @@ def __init__(self, *, debug=...): if router is None: router = UrlDispatcher() + else: + warnings.warn("router argument is deprecated", DeprecationWarning, + stacklevel=2) assert isinstance(router, AbstractRouter), router if loop is not None: diff --git a/docs/web_reference.rst b/docs/web_reference.rst index 2f60dd5abd5..e1cf79f7bc9 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -1243,6 +1243,11 @@ duplicated like one using :meth:`Application.copy`. creates :class:`UrlDispatcher` by default if *router* is ``None``. + .. deprecated:: 3.3 + + The custom routers support is deprecated, the parameter will + be removed in 4.0. + :param middlewares: :class:`list` of middleware factories, see :ref:`aiohttp-web-middlewares` for details. diff --git a/tests/test_web_app.py b/tests/test_web_app.py index dd2ec2f7809..f210ed40e50 100644 --- a/tests/test_web_app.py +++ b/tests/test_web_app.py @@ -132,7 +132,8 @@ async def cb(app): def test_non_default_router(): router = mock.Mock(spec=AbstractRouter) - app = web.Application(router=router) + with pytest.warns(DeprecationWarning): + app = web.Application(router=router) assert router is app.router diff --git a/tests/test_web_urldispatcher.py b/tests/test_web_urldispatcher.py index 5deefcf6708..9a83dadc7f9 100644 --- a/tests/test_web_urldispatcher.py +++ b/tests/test_web_urldispatcher.py @@ -311,7 +311,8 @@ class MyRouter(abc.AbstractRouter): async def resolve(self, request): raise web.HTTPPreconditionFailed() - app = web.Application(router=MyRouter()) + with pytest.warns(DeprecationWarning): + app = web.Application(router=MyRouter()) client = await aiohttp_client(app)