diff --git a/src/flask/sansio/app.py b/src/flask/sansio/app.py index ceab45cb..05c75b5d 100644 --- a/src/flask/sansio/app.py +++ b/src/flask/sansio/app.py @@ -672,10 +672,19 @@ class App(Scaffold): def reverse(s): return s[::-1] + You must include parentheses when using this decorator, + even if no arguments are provided. + :param name: the optional name of the filter, otherwise the function name will be used. """ + if callable(name): + raise TypeError( + "Did you mean to use @app.template_filter()? " + "Missing parentheses () in decorator" + ) + def decorator(f: T_template_filter) -> T_template_filter: self.add_template_filter(f, name=name) return f diff --git a/tests/test_templating.py b/tests/test_templating.py index c9fb3754..423b0134 100644 --- a/tests/test_templating.py +++ b/tests/test_templating.py @@ -130,6 +130,14 @@ def test_template_filter(app): assert app.jinja_env.filters["my_reverse"]("abcd") == "dcba" +def test_template_filter_requires_parentheses(app): + with pytest.raises(TypeError): + + @app.template_filter + def my_reverse(s): + return s[::-1] + + def test_add_template_filter(app): def my_reverse(s): return s[::-1]