diff --git a/CHANGES.rst b/CHANGES.rst index 2844c4c01..09a0c6bb2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,5 +1,14 @@ .. currentmodule:: jinja2 +Version 3.1.7 +------------- + +Unreleased + +- Add type annotation to ``FILTERS`` and ``TESTS`` + :issue:`2120`, :pr:`2141` + + Version 3.1.6 ------------- diff --git a/src/jinja2/__init__.py b/src/jinja2/__init__.py index 1a423a3ea..26e1ba883 100644 --- a/src/jinja2/__init__.py +++ b/src/jinja2/__init__.py @@ -35,4 +35,4 @@ from .utils import pass_eval_context as pass_eval_context from .utils import select_autoescape as select_autoescape -__version__ = "3.1.6" +__version__ = "3.1.7" diff --git a/src/jinja2/filters.py b/src/jinja2/filters.py index 2bcba4fbd..0be0311ad 100644 --- a/src/jinja2/filters.py +++ b/src/jinja2/filters.py @@ -41,7 +41,7 @@ def __html__(self) -> str: pass -F = t.TypeVar("F", bound=t.Callable[..., t.Any]) +FilterFunction = t.Callable[..., t.Any] K = t.TypeVar("K") V = t.TypeVar("V") @@ -1815,7 +1815,7 @@ async def async_select_or_reject( yield item -FILTERS = { +FILTERS: t.Dict[str, FilterFunction] = { "abs": abs, "attr": do_attr, "batch": do_batch, diff --git a/src/jinja2/tests.py b/src/jinja2/tests.py index 1a59e3703..17e21d36b 100644 --- a/src/jinja2/tests.py +++ b/src/jinja2/tests.py @@ -12,6 +12,9 @@ from .environment import Environment +TestFunction = t.Callable[..., t.Any] + + def test_odd(value: int) -> bool: """Return true if the variable is odd.""" return value % 2 == 1 @@ -213,7 +216,7 @@ def test_in(value: t.Any, seq: t.Container[t.Any]) -> bool: return value in seq -TESTS = { +TESTS: t.Dict[str, TestFunction] = { "odd": test_odd, "even": test_even, "divisibleby": test_divisibleby,