Skip to content
This repository

Outdent only if raise has been indented in multiple inheritance error handling. #83

Closed
wants to merge 2 commits into from

2 participants

Mounier Florian Armin Ronacher
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 18 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 1  jinja2/compiler.py
  2. +16 1 jinja2/testsuite/inheritance.py
3  jinja2/compiler.py
@@ -894,12 +894,13 @@ def visit_Extends(self, node, frame):
894 894 self.indent()
895 895 self.writeline('raise TemplateRuntimeError(%r)' %
896 896 'extended multiple times')
897   - self.outdent()
898 897
899 898 # if we have a known extends already we don't need that code here
900 899 # as we know that the template execution will end here.
901 900 if self.has_known_extends:
902 901 raise CompilerExit()
  902 + else:
  903 + self.outdent()
903 904
904 905 self.writeline('parent_template = environment.get_template(', node)
905 906 self.visit(node.template, frame)
17 jinja2/testsuite/inheritance.py
@@ -13,7 +13,7 @@
13 13 from jinja2.testsuite import JinjaTestCase
14 14
15 15 from jinja2 import Environment, DictLoader
16   -
  16 +from jinja2.exceptions import TemplateRuntimeError
17 17
18 18 LAYOUTTEMPLATE = '''\
19 19 |{% block block1 %}block 1 from layout{% endblock %}
@@ -141,6 +141,21 @@ def test_multi_inheritance(self):
141 141 assert tmpl.render(master='master1') == 'MASTER1CHILD'
142 142 assert tmpl.render() == 'MASTER1CHILD'
143 143
  144 + def test_forbidden_multi_inheritance(self):
  145 + env = Environment(loader=DictLoader({
  146 + 'master1': '1',
  147 + 'master2': '2',
  148 + 'child': "{% extends 'master1' %}{% extends 'master2' %}"
  149 + }))
  150 +
  151 + tmpl = env.get_template('child')
  152 + try:
  153 + tmpl.render()
  154 + except TemplateRuntimeError, e:
  155 + assert e.message == 'extended multiple times'
  156 + else:
  157 + assert False, 'Must raise on multiple inheritance'
  158 +
144 159 def test_scoped_block(self):
145 160 env = Environment(loader=DictLoader({
146 161 'master.html': '{% for item in seq %}[{% block item scoped %}'

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.