Issues

Issue #146 resolved

Empty block in middle of %if...%elif...%elif...%else...%endif doesn't get a pass in the Python, leading to an IndentationError

guest
created an issue

How-To-Reproduce:

% if True: test % elif lose: do nothing % elif False: broken % endif

Results:

An IndentationError pointing at the next line of code after the do-nothing block, complaining that Python was expecting an indented block.

Workaround: Add <%pass%> to the do-nothing block

Comments (6)

  1. guest reporter

    Don't you have to add a 'pass' in that same situation in Python? Isn't this asking mako behavior to diverge from Python unnecessarily? Although it would indeed be more convenient to not have to manually insert the pass statement.

  2. Mike Bayer repo owner

    the patch is in 1b4d1fb7e8a33ce3f285a0bbd5b2a1407a75b96c but doesn't actually fix the above test case, it appears that the comment line screws it up:

    1. !python from mako.template import Template template = r""" % if True: test % elif lose:
      1. do nothing % elif False: broken % endif """

    t = Template(template) print t.render()

    Traceback (most recent call last): File "test.py", line 12, in <module> t = Template(template) File "/Users/classic/dev/mako/mako/template.py", line 258, in init (code, module) = _compile_text(self, text, filename) File "/Users/classic/dev/mako/mako/template.py", line 606, in _compile_text code = compile(source, cid, 'exec') File "memory:0x1004a68d0", line 29 elif False: ^ IndentationError: expected an indented block

    taking out the comment, it's fine:

    1. !python from mako.template import Template template = r""" % if True: test % elif lose: % elif False: broken % endif """

    t = Template(template) print t.render()

  3. Log in to comment