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

unnecessary writer statements with \ #155

Closed
sqlalchemy-bot opened this Issue Nov 12, 2010 · 2 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Nov 12, 2010

Migrated issue, originally created by Michael Bayer (@zzzeek)

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.

import mako.template
print mako.template.Template("<% pass %>\\\nFoo").code

...
       # SOURCE LINE 1
       pass

       __M_writer(u'')
       # 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):

--- 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
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 12, 2010

Michael Bayer (@zzzeek) wrote:

6eea951

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 12, 2010

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