Skip to content
Myr

Merge remote-tracking branch 'origin/3.0.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents 3aeefed, 024fa10 · Browse files · 9 files+61 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+61 added−8 removed

  • tests:+37 added−1 removed
  • other:+24 added−7 removed

9 files+61 added−8 removed

modified:src/jinja2/compiler.py+6 added-1 removed
554 unmodified lines
555 self.tests,556 visitor.tests,557 "tests",558 ):559 for name in names:559 for name in sorted(names):560 if name not in id_map:561 id_map[name] = self.temporary_identifier()562563 # add check during runtime that dependencies used inside of executed
725 unmodified lines
1289 self.write(")")1290 self.write(", loop)")1291 self.end_write(frame)12921293 # at the end of the iteration, clear any assignments made in the1294 # loop from the top level1295 if self._assign_stack:1296 self._assign_stack[-1].difference_update(loop_frame.symbols.stores)12971298 def visit_If(self, node: nodes.If, frame: Frame) -> None:1299 if_frame = frame.soft()1300 self.writeline("if ", node)1301 self.visit(node.test, if_frame)
658 unmodified lines
modified:src/jinja2/idtracking.py+1 added-1 removed
147 unmodified lines
148 rv: t.Dict[str, str] = {}149 node: t.Optional["Symbols"] = self150151 while node is not None:152 for name in node.stores:152 for name in sorted(node.stores):153 if name not in rv:154 rv[name] = self.find_ref(name) # type: ignore155156 node = node.parent
162 unmodified lines
modified:src/jinja2/runtime.py+2 added-1 removed
913 unmodified lines
914 __truediv__ = __rtruediv__ = _fail_with_undefined_error915 __floordiv__ = __rfloordiv__ = _fail_with_undefined_error916 __mod__ = __rmod__ = _fail_with_undefined_error917 __pos__ = __neg__ = _fail_with_undefined_error918 __call__ = __getitem__ = __contains__ = _fail_with_undefined_error918 __call__ = __getitem__ = _fail_with_undefined_error919 __lt__ = __le__ = __gt__ = __ge__ = _fail_with_undefined_error920 __int__ = __float__ = __complex__ = _fail_with_undefined_error921 __pow__ = __rpow__ = _fail_with_undefined_error922
167 unmodified lines
10901091 __slots__ = ()1092 __iter__ = __str__ = __len__ = Undefined._fail_with_undefined_error1093 __eq__ = __ne__ = __bool__ = __hash__ = Undefined._fail_with_undefined_error1094 __contains__ = Undefined._fail_with_undefined_error109510961097# Remove slots attributes, after the metaclass is applied they are1098# unneeded and contain wrong data for subclasses.
6 unmodified lines
modified:tests/test_api.py+2 added-1 removed
314 unmodified lines
315 assert env.from_string("{{ missing is not defined }}").render() == "True"316 assert env.from_string("{{ foo.missing }}").render(foo=42) == ""317 assert env.from_string("{{ not missing }}").render() == "True"318 pytest.raises(UndefinedError, env.from_string("{{ missing - 1}}").render)319 pytest.raises(UndefinedError, env.from_string("{{ 'foo' in missing }}").render)319 assert env.from_string("{{ 'foo' in missing }}").render() == "False"320 und1 = Undefined(name="x")321 und2 = Undefined(name="y")322 assert und1 == und2323 assert und1 != 42
50 unmodified lines
374 env = Environment(undefined=StrictUndefined)375 pytest.raises(UndefinedError, env.from_string("{{ missing }}").render)376 pytest.raises(UndefinedError, env.from_string("{{ missing.attribute }}").render)377 pytest.raises(UndefinedError, env.from_string("{{ missing|list }}").render)378 pytest.raises(UndefinedError, env.from_string("{{ 'foo' in missing }}").render)379 assert env.from_string("{{ missing is not defined }}").render() == "True"380 pytest.raises(381 UndefinedError, env.from_string("{{ foo.missing }}").render, foo=42382 )
52 unmodified lines
added:tests/test_compile.py+28 added
1import os2import re34from jinja2.environment import Environment5from jinja2.loaders import DictLoader678def test_filters_deterministic(tmp_path):9 src = "".join(f"{{{{ {i}|filter{i} }}}}" for i in range(10))10 env = Environment(loader=DictLoader({"foo": src}))11 env.filters.update(dict.fromkeys((f"filter{i}" for i in range(10)), lambda: None))12 env.compile_templates(tmp_path, zip=None)13 name = os.listdir(tmp_path)[0]14 content = (tmp_path / name).read_text("utf8")15 expect = [f"filters['filter{i}']" for i in range(10)]16 found = re.findall(r"filters\['filter\d']", content)17 assert found == expect181920def test_import_as_with_context_deterministic(tmp_path):21 src = "\n".join(f'{{% import "bar" as bar{i} with context %}}' for i in range(10))22 env = Environment(loader=DictLoader({"foo": src}))23 env.compile_templates(tmp_path, zip=None)24 name = os.listdir(tmp_path)[0]25 content = (tmp_path / name).read_text("utf8")26 expect = [f"'bar{i}': " for i in range(10)]27 found = re.findall(r"'bar\d': ", content)[:10]28 assert found == expect
modified:tests/test_regression.py+7 added
744 unmodified lines
745746 tmpl = env.get_template("base")747 assert tmpl.render() == "42 y"748749 def test_nested_loop_scoping(self, env):750 tmpl = env.from_string(751 "{% set output %}{% for x in [1,2,3] %}hello{% endfor %}"752 "{% endset %}{{ output }}"753 )754 assert tmpl.render() == "hellohellohello"755756757@pytest.mark.parametrize("unicode_char", ["\N{FORM FEED}", "\x85"])758def test_unicode_whitespace(env, unicode_char):759 content = "Lorem ipsum\n" + unicode_char + "\nMore text"760 tmpl = env.from_string(content)
1 unmodified line
modified:CHANGES.rst+6 added-1 removed
7 unmodified lines
89Version 3.0.210-------------1112Unreleased12- Fix a loop scoping bug that caused assignments in nested loops13 to still be referenced outside of it. :issue:`1427`14- Make ``compile_templates`` deterministic for filter and import15 names. :issue:`1452, 1453`16- Revert an unintended change that caused ``Undefined`` to act like17 ``StrictUndefined`` for the ``in`` operator. :issue:`1448`181920Version 3.0.121-------------
876 unmodified lines
modified:CONTRIBUTING.rst+8 added-2 removed
90 unmodified lines
91 default Pallets remote is "origin".9293 .. code-block:: text9495 git remote add fork https://github.com/{username}/jinja95 $ git remote add fork https://github.com/{username}/jinja9697- Create a virtualenv.9899 .. code-block:: text
6 unmodified lines
106 .. code-block:: text107108 > env\Scripts\activate109110- Upgrade pip and setuptools.111112 .. code-block:: text113114 $ python -m pip install --upgrade pip setuptools115116- Install the development dependencies, then install Jinja in editable117 mode.118119 .. code-block:: text
23 unmodified lines
143144 .. code-block:: text145146 $ git fetch origin141 $ git checkout -b your-branch-name origin/1.1.x147 $ git checkout -b your-branch-name origin/3.0.x148149 If you're submitting a feature addition or change, branch off of the150 "main" branch.151
71 unmodified lines
modified:README.rst+1 added-1 removed
33 unmodified lines
34.. code-block:: text3536 $ pip install -U Jinja23738.. _pip: https://pip.pypa.io/en/stable/quickstart/38.. _pip: https://pip.pypa.io/en/stable/getting-started/394041In A Nutshell42-------------
36 unmodified lines