Skip to content

Commit

Permalink
Deprecate custom router (#3021)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored May 24, 2018
1 parent bdb182a commit af53fe0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/3021.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate custom application's router.
3 changes: 3 additions & 0 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion tests/test_web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit af53fe0

Please sign in to comment.