From 653ac7ee1421fbd0135ff4e68736b7320c4fcdb5 Mon Sep 17 00:00:00 2001 From: Nikita Antonenkov Date: Sat, 6 Apr 2019 22:23:50 +0300 Subject: [PATCH 1/2] Fix app.patch decorator docstring typo --- sanic/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/app.py b/sanic/app.py index a32d924c..94eb8bed 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -332,7 +332,7 @@ class Sanic: name=None, ): """ - Add an API URL under the **DELETE** *HTTP* method + Add an API URL under the **PATCH** *HTTP* method :param uri: URL to be tagged to **PATCH** method of *HTTP* :param host: Host IP or FQDN for the service to use From de582d2fc70d6f4f27f09ea01246ae7bc58df3d8 Mon Sep 17 00:00:00 2001 From: Nikita Antonenkov Date: Sat, 6 Apr 2019 22:26:49 +0300 Subject: [PATCH 2/2] Refactor the app.route decorator --- sanic/app.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 94eb8bed..493b5d94 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -180,27 +180,28 @@ class Sanic: strict_slashes = self.strict_slashes def response(handler): - args = [key for key in signature(handler).parameters.keys()] - if args: - if stream: - handler.is_stream = stream + args = list(signature(handler).parameters.keys()) - self.router.add( - uri=uri, - methods=methods, - handler=handler, - host=host, - strict_slashes=strict_slashes, - version=version, - name=name, - ) - return handler - else: + if not args: raise ValueError( "Required parameter `request` missing " "in the {0}() route?".format(handler.__name__) ) + if stream: + handler.is_stream = stream + + self.router.add( + uri=uri, + methods=methods, + handler=handler, + host=host, + strict_slashes=strict_slashes, + version=version, + name=name, + ) + return handler + return response # Shorthand method decorators