-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Milestone
Description
Running examples/basic/test.py fails/has been failing with what appears to be a parse error since jinja 2.8 up to and including 3.1.4
this is slightly pseudocode since older versions don't install cleanly; I can provide the real one if it is necessary
for i in $(git tag | sed -e '/rc/d; /\.x/d; /a[0-9]/d'); do
py_env="venv$i"
python3 -m venv "$py_env"
git checkout --force $i
$py_env/bin/pip install .
$py_env/bin/python -u examples/basic/test.py
doneproduces
$ ./venv2.8/bin/python -u examples/basic/test.py
Traceback (most recent call last):
File "/Users/foo/Projects/jinja/examples/basic/test.py", line 26, in <module>
tmpl = env.get_template("child.html")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/environment.py", line 812, in get_template
return self._load_template(name, self.make_globals(globals))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/environment.py", line 786, in _load_template
template = self.loader.load(self, name, globals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/loaders.py", line 125, in load
code = environment.compile(source, name, filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/environment.py", line 565, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/environment.py", line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<unknown>", line 2, in <module>
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/environment.py", line 470, in _parse
return Parser(self, source, name, encode_filename(filename)).parse()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/parser.py", line 897, in parse
result = nodes.Template(self.subparse(), lineno=1)
^^^^^^^^^^^^^^^
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/parser.py", line 884, in subparse
self.stream.expect('block_end')
File "/Users/foo/Projects/jinja/venv2.8/lib/python3.12/site-packages/jinja2/lexer.py", line 371, in expect
raise TemplateSyntaxError("expected token %r, got %r" %
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '='
I found the seemingly relevant commit which discusses assigning include statements to a Name but due to the lack of a formal grammar (1194 👀) it's hard to know if this was missed in the actual tests, was supposed to work even back in 2.8, or just got overlooked during some refactoring
Environment:
- Python version: 3.12 (I can of course try with other versions but I don't believe this is relevant)
- Jinja versions: 2.8, 2.8.1, 2.9, 2.9.1, 2.9.2, 2.9.3, 2.9.4, 2.9.5, 2.9.6, 2.10, 2.10.1, 2.10.2, 2.10.3, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4
JamesParrott
Metadata
Metadata
Assignees
Labels
No labels