Skip to content
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

ISSUE-1902 Fix Template::is_up_to_date contract #1903

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/jinja2/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down