Skip to content
Myr

Add stricter checking to "from ... import ..."

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

Currently token parsing on "from ... import ..." is rather "loose" — it sees the following "invalid" code as perfectly valid: {% from "functions" import my_function, %} {% from "functions" import, %} {% from "functions" import %} This is caused by the parser ignoring non-name values where there should be names, either as the first value or after commas. This commit ensures only name values are allowed as the first value and any values after commas in the import section.

authored by Jack Wilsdon · committed by David Lord · parent 2c61df1 · Browse files · 1 file+1 added−1 removed
This commit

State

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

Diff stats

1 file+1 added−1 removed

  • other:+1 added−1 removed

1 file+1 added−1 removed

modified:jinja2/parser.py+1 added-1 removed
332 unmodified lines
333 node.names.append(target.name)334 if parse_context() or self.stream.current.type != 'comma':335 break336 else:337 break337 self.stream.expect('name')338 if not hasattr(node, 'with_context'):339 node.with_context = False340 self.stream.skip_if('comma')341 return node
563 unmodified lines