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.
if parse_context() or self.stream.current.type != 'comma':
break
else:
- break
+ self.stream.expect('name')
if not hasattr(node, 'with_context'):
node.with_context = False
self.stream.skip_if('comma')