feat: support call template_filter without parens #5736
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enhances the App.template_filter decorator to support:
@app.template_filter
(without parentheses)It also ensures that the original usage remains fully supported, with no breaking changes:
@app.template_filter()
@app.template_filter(name="...")
@app.template_filter("...")
I’m not fully confident in the solution, so I’d like to confirm it first. If it’s good, I’ll apply the same change to template_global and template_test.
I considered the following implementation options:
However, this would be a breaking change for calls like @app.template_filter(name="..."), so I decided to keep the original parameter name for backward compatibility.
This approach is type-safe, but it introduces the awkward case where both func_or_name and name are provided at the same time. It could also be confusing for users reading the function signature.
So eventually, I decided to keep the original function parameter and distinguish the usage using
if callable(name):
. I’d like to discuss whether there’s a better approach, and I’m open to making improvements based on feedback and suggestions.fixes #5729
.. versionchanged::
entries in any relevant code docs.