From a45fce84960e3b97fe3ecc2f11de1ba613b8c5c4 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 5 Feb 2015 12:32:47 -0800 Subject: [PATCH 1/4] fix grammar in preprocess_request() docstring --- flask/app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flask/app.py b/flask/app.py index 2f273592..1aac95eb 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1710,8 +1710,9 @@ class Flask(_PackageBoundObject): def preprocess_request(self): """Called before the actual request dispatching and will - call every as :meth:`before_request` decorated function. - If any of these function returns a value it's handled as + call each :meth:`before_request` decorated function, passing no + arguments. + If any of these functions returns a value, it's handled as if it was the return value from the view and further request handling is stopped. From eccee36964832577aad8d8a3108b7f39958ba8b0 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 5 Feb 2015 12:38:34 -0800 Subject: [PATCH 2/4] Document required signature of before_request functions Unless you happened to also read preprocess_request()'s docstring, it wasn't not obvious that return values from these functions are treated as response values. --- flask/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flask/app.py b/flask/app.py index 1aac95eb..bd721a4d 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1243,7 +1243,13 @@ class Flask(_PackageBoundObject): @setupmethod def before_request(self, f): - """Registers a function to run before each request.""" + """Registers a function to run before each request. + + The function will be called without any arguments. + If the function returns a non-None value, it's handled as + if it was the return value from the view and further + request handling is stopped. + """ self.before_request_funcs.setdefault(None, []).append(f) return f From 6a2524634dec3a7bc71a8b7076ab937d77253c6a Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 5 Feb 2015 12:45:11 -0800 Subject: [PATCH 3/4] Document that the return values of teardown functions are ignored --- flask/app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flask/app.py b/flask/app.py index bd721a4d..c45d640d 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1304,6 +1304,8 @@ class Flask(_PackageBoundObject): When a teardown function was called because of a exception it will be passed an error object. + The return values of teardown functions are ignored. + .. admonition:: Debug Note In debug mode Flask will not tear down a request on an exception @@ -1338,6 +1340,8 @@ class Flask(_PackageBoundObject): When a teardown function was called because of an exception it will be passed an error object. + The return values of teardown functions are ignored. + .. versionadded:: 0.9 """ self.teardown_appcontext_funcs.append(f) From fe6bcffdad73fc8f683dadf1a86229fdfd3a571c Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 5 Feb 2015 12:45:59 -0800 Subject: [PATCH 4/4] Document required signature of before_first_request-decorated functions --- flask/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flask/app.py b/flask/app.py index c45d640d..467725c1 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1258,6 +1258,9 @@ class Flask(_PackageBoundObject): """Registers a function to be run before the first request to this instance of the application. + The function will be called without any arguments and its return + value is ignored. + .. versionadded:: 0.8 """ self.before_first_request_funcs.append(f)