Skip to content
Myr

Further error message improvement, this time for #341.

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 5d659db · Browse files · 2 files+12 added−0 removed
This commit

State

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

Diff stats

2 files+12 added−0 removed

  • tests:+3 added−0 removed
  • other:+9 added−0 removed

2 files+12 added−0 removed

modified:jinja2/parser.py+9 added
210 unmodified lines
211 def parse_block(self):212 node = nodes.Block(lineno=next(self.stream).lineno)213 node.name = self.stream.expect('name').value214 node.scoped = self.stream.skip_if('name:scoped')215216 # common problem people encounter when switching from django217 # to jinja. we do not support hyphens in block names, so let's218 # raise a nicer error message in that case.219 if self.stream.current.type == 'sub':220 self.fail('Block names in Jinja have to be valid Python '221 'identifiers and may not contain hypens, use an '222 'underscore instead.')223224 node.body = self.parse_statements(('name:endblock',), drop_needle=True)225 self.stream.skip_if('name:' + node.name)226 return node227
650 unmodified lines
modified:tests/test_parser.py+3 added
139 unmodified lines
140 assert_error('{% for item in seq %}',141 "Unexpected end of template. Jinja was looking for the "142 "following tags: 'endfor' or 'else'. The innermost block "143 "that needs to be closed is 'for'.")144 assert_error('{% block foo-bar-baz %}',145 "Block names in Jinja have to be valid Python identifiers "146 "and may not contain hypens, use an underscore instead.")