Skip to content

Commit

Permalink
Fix #1993: Deprecate registering synchronous web handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jul 25, 2017
1 parent 0d9abc9 commit 153197f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def __init__(self, method, handler, *,
issubclass(handler, AbstractView)):
pass
else:
warnings.warn("Bare functions are deprecated, "
"use async ones", DeprecationWarning)

@wraps(handler)
@asyncio.coroutine
def handler_wrapper(*args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions changes/1993.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate registering synchronous web handlers
8 changes: 8 additions & 0 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,11 @@ def test_convert_empty_path_to_slash_on_freezing(router):
assert resource.get_info() == {'path': ''}
router.freeze()
assert resource.get_info() == {'path': '/'}


def test_deprecate_non_coroutine(router):
def handler(request):
pass

with pytest.warns(DeprecationWarning):
router.add_route('GET', '/handler', handler)

0 comments on commit 153197f

Please sign in to comment.