1. Michael Bayer
  2. mako
  3. Issues


Issue #155 resolved

unnecessary writer statements with \

Michael Bayer
repo owner created an issue

the use of the end-of-line continuation (backslash) syntax can result in the generated python module for a template to contain unnecessary calls to write empty strings.

  1. !python

import mako.template print mako.template.Template("<% pass %>


  1. SOURCE LINE 1 pass


  1. SOURCE LINE 2 M_writer(u'Foo') ...

I believe these calls `M_writer(u'')` are unnecessary. I have a few templates that use a lot of line continuations and so I see a lot of these in the generated code.

A really simple change in mako/lexer.py appears to optimize these calls away (patch is against the 0.3.6 candidate, tag Mako-c8598ab628a0da0d55857196627753dad9849a39):

  1. !diff --- mako/lexer.py.orig 2010-11-09 19:44:52.000000000 -0500 +++ mako/lexer.py 2010-11-12 12:17:43.348306483 -0500 @@ -331,7 +331,8 @@

if match: text = match.group(1) - self.append_node(parsetree.Text, text) + if text: + self.append_node(parsetree.Text, text) return True else: return False