Skip to content

Fix template decorators to work without parentheses #5743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ding-alex
Copy link

Description

This PR fixes an issue where template decorators like @app.template_filter don't work when used without parentheses. The fix allows the decorators to be used in both ways:

  • @app.template_filter (without parentheses)
  • @app.template_filter() (with empty parentheses)
  • @app.template_filter("my_filter") (with a name argument)

The following decorators have been fixed:

  • template_filter, template_test, template_global in Flask
  • app_template_filter, app_template_test, app_template_global in Blueprint

Changes

  • Modified the decorators to check if they're being called with a callable (function) as the first argument
  • If so, apply the decorator directly to the function
  • Added tests to verify the fix

Related Issue

Fixes #5729

Testing

Added tests in tests/test_decorator_no_parens.py to verify that all the decorators work without parentheses.


Pull Request opened by Augment Code with guidance from the PR author

strugee and others added 4 commits May 20, 2025 12:26
This fixes an issue where template decorators like @app.template_filter
don't work when used without parentheses. The fix allows the decorators
to be used in both ways:

- @app.template_filter
- @app.template_filter()

The following decorators have been fixed:
- template_filter, template_test, template_global in Flask
- app_template_filter, app_template_test, app_template_global in Blueprint

Fixes pallets#5729
@ding-alex ding-alex closed this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The template_filter decorator doesn't work if you don't pass an argument
3 participants