New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sqlalchemy-bot opened this Issue Aug 10, 2010 · 5 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Aug 10, 2010

Migrated issue, originally created by Anonymous

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


Attachments: 146.patch | 146.2.patch | 146.3.patch

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Aug 10, 2010

Michael Bayer (@zzzeek) wrote:

a very old bug which I thought we had a bug report for, thought we fixed, but all these assumptions (except the first) are wrong.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Jun 25, 2011

Anonymous wrote:

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.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Apr 3, 2012

Michael Bayer (@zzzeek) wrote:

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

from mako.template import Template
template = r"""
% if True:
test
% elif lose:
##  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:

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

t = Template(template)
print t.render()
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Apr 6, 2012

Michael Bayer (@zzzeek) wrote:

great, 8cce610 and we're done ! thanks!

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Apr 6, 2012

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment