From 0bcbad24fd594aea4bf4744ee681874a45327ec5 Mon Sep 17 00:00:00 2001 From: Raiko Wielk Date: Wed, 25 Oct 2023 09:28:56 +0200 Subject: [PATCH] ISSUE-1902 Fix Template::is_up_to_date contract ISSUE-1902 CHANGES.rst ISSUE-1902 Add PR info to CHANGES.rst ISSUE-1902 Test --- CHANGES.rst | 1 + src/jinja2/environment.py | 2 +- tests/test_regression.py | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index bbfad1356..80efbad0d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Version 3.2.0 Unreleased +- Fix Template's type hint contract :pr: `1903` - Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``. :pr:`1793` - Use ``flit_core`` instead of ``setuptools`` as build backend. diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py index c9afae311..bed687dbf 100644 --- a/src/jinja2/environment.py +++ b/src/jinja2/environment.py @@ -1493,7 +1493,7 @@ def is_up_to_date(self) -> bool: """If this variable is `False` there is a newer version available.""" if self._uptodate is None: return True - return self._uptodate() + return self._uptodate() if callable(self._uptodate) else self._uptodate @property def debug_info(self) -> t.List[t.Tuple[int, int]]: diff --git a/tests/test_regression.py b/tests/test_regression.py index 46e492bdd..7ab417e79 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -11,6 +11,28 @@ class TestCorner: + def test_uptodate_loader(self, env): + class UpToDateDictLoader(DictLoader): + def get_source(self, environment: "Environment", template: str): + contents, path, uptodate = super().get_source(environment, template) + return contents, path, True + + env = Environment( + loader=UpToDateDictLoader( + { + "a.html": """ + {%- set foo = 'bar' -%} + {% include 'x.html' -%}{% include 'x.html' -%} + """, + "x.html": """{{ foo }}|{{ test }}""", + } + ) + ) + + a = env.get_template("a.html") + + assert a.render(test="x").strip() == "bar|xbar|x" + def test_assigned_scoping(self, env): t = env.from_string( """