Skip to content
Myr

Merge branch '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 e20a52e, b7d12b6 · Browse files · 6 files+58 added−35 removed
This commit

State

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

Diff stats

6 files+58 added−35 removed

  • tests:+47 added−31 removed
  • other:+11 added−4 removed

6 files+58 added−35 removed

modified:src/jinja2/compiler.py+1 added-3 removed
1088 unmodified lines
1089 f_name = f"make_module{self.choose_async('_async')}"1090 self.write(1091 f"{f_name}(context.get_all(), True, {self.dump_local_context(frame)})"1092 )1093 elif self.environment.is_async:1094 self.write("_get_default_module_async()")1093 else:1096 self.write("_get_default_module(context)")1094 self.write(f"_get_default_module{self.choose_async('_async')}(context)")10951096 def visit_Import(self, node: nodes.Import, frame: Frame) -> None:1097 """Visit regular imports."""1098 self.writeline(f"{frame.symbols.ref(node.target)} = ", node)
859 unmodified lines
modified:src/jinja2/loaders.py+3 added-1 removed
268 unmodified lines
269 package_name: str,270 package_path: "str" = "templates",271 encoding: str = "utf-8",272 ) -> None:273 package_path = os.path.normpath(package_path).rstrip(os.path.sep)274275 # normpath preserves ".", which isn't valid in zip paths.276 if package_path == os.path.curdir:277 package_path = ""278 elif package_path[:2] == os.path.curdir + os.path.sep:279 package_path = package_path[2:]280278 package_path = os.path.normpath(package_path).rstrip(os.path.sep)281 self.package_path = package_path282 self.package_name = package_name283 self.encoding = encoding284
360 unmodified lines
modified:tests/test_async.py+23 added
187 unmodified lines
188 assert not hasattr(m, "__missing")189 assert m.variable == 42190 assert not hasattr(m, "notthere")191192 def test_import_with_globals(self, test_env_async):193 t = test_env_async.from_string(194 '{% import "module" as m %}{{ m.test() }}', globals={"foo": 42}195 )196 assert t.render() == "[42|23]"197198 t = test_env_async.from_string('{% import "module" as m %}{{ m.test() }}')199 assert t.render() == "[|23]"200201 def test_import_with_globals_override(self, test_env_async):202 t = test_env_async.from_string(203 '{% set foo = 41 %}{% import "module" as m %}{{ m.test() }}',204 globals={"foo": 42},205 )206 assert t.render() == "[42|23]"207208 def test_from_import_with_globals(self, test_env_async):209 t = test_env_async.from_string(210 '{% from "module" import test %}{{ test() }}',211 globals={"foo": 42},212 )213 assert t.render() == "[42|23]"214215216class TestAsyncIncludes:217 def test_context_include(self, test_env_async):218 t = test_env_async.from_string('{% include "header" %}')219 assert t.render(foo=42) == "[42|23]"
441 unmodified lines
modified:tests/test_imports.py+13 added-31 removed
97 unmodified lines
98 with pytest.raises(UndefinedError, match="does not export the requested name"):99 t.render()100101 def test_import_with_globals(self, test_env):102 env = Environment(103 loader=DictLoader(104 {105 "macros": "{% macro test() %}foo: {{ foo }}{% endmacro %}",106 "test": "{% import 'macros' as m %}{{ m.test() }}",107 "test1": "{% import 'macros' as m %}{{ m.test() }}",108 }109 )102 t = test_env.from_string(103 '{% import "module" as m %}{{ m.test() }}', globals={"foo": 42}104 )111 tmpl = env.get_template("test", globals={"foo": "bar"})112 assert tmpl.render() == "foo: bar"105 assert t.render() == "[42|23]"106114 tmpl = env.get_template("test1")115 assert tmpl.render() == "foo: "107 t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')108 assert t.render() == "[|23]"109110 def test_import_with_globals_override(self, test_env):118 env = Environment(119 loader=DictLoader(120 {121 "macros": "{% set foo = '42' %}{% macro test() %}"122 "foo: {{ foo }}{% endmacro %}",123 "test": "{% from 'macros' import test %}{{ test() }}",124 }125 )111 t = test_env.from_string(112 '{% set foo = 41 %}{% import "module" as m %}{{ m.test() }}',113 globals={"foo": 42},114 )127 tmpl = env.get_template("test", globals={"foo": "bar"})128 assert tmpl.render() == "foo: 42"115 assert t.render() == "[42|23]"116117 def test_from_import_with_globals(self, test_env):131 env = Environment(132 loader=DictLoader(133 {134 "macros": "{% macro testing() %}foo: {{ foo }}{% endmacro %}",135 "test": "{% from 'macros' import testing %}{{ testing() }}",136 }137 )118 t = test_env.from_string(119 '{% from "module" import test %}{{ test() }}',120 globals={"foo": 42},121 )139 tmpl = env.get_template("test", globals={"foo": "bar"})140 assert tmpl.render() == "foo: bar"122 assert t.render() == "[42|23]"123124125class TestIncludes:126 def test_context_include(self, test_env):
79 unmodified lines
modified:tests/test_loader.py+11 added
337 unmodified lines
338def test_package_zip_list(package_zip_loader):339 assert package_zip_loader.list_templates() == ["foo/test.html", "test.html"]340341342@pytest.mark.parametrize("package_path", ["", ".", "./"])343def test_package_zip_omit_curdir(package_zip_loader, package_path):344 """PackageLoader should not add or include "." or "./" in the root345 path, it is invalid in zip paths.346 """347 loader = PackageLoader("t_pack", package_path)348 assert loader.package_path == ""349 source, _, _ = loader.get_source(None, "templates/foo/test.html")350 assert source.rstrip() == "FOO"351352353def test_pep_451_import_hook():354 class ImportHook(importlib.abc.MetaPathFinder, importlib.abc.Loader):355 def find_spec(self, name, path=None, target=None):356 if name != "res":
25 unmodified lines
modified:CHANGES.rst+7 added
7 unmodified lines
89Version 3.0.210-------------1112Released 2021-10-041314- Fix a loop scoping bug that caused assignments in nested loops15 to still be referenced outside of it. :issue:`1427`16- Make ``compile_templates`` deterministic for filter and import17 names. :issue:`1452, 1453`18- Revert an unintended change that caused ``Undefined`` to act like19 ``StrictUndefined`` for the ``in`` operator. :issue:`1448`20- Imported macros have access to the current template globals in async21 environments. :issue:`1494`22- ``PackageLoader`` will not include a current directory (.) path23 segment. This allows loading templates from the root of a zip24 import. :issue:`1467`252627Version 3.0.128-------------
876 unmodified lines