Skip to content
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
Closed

unnecessary writer statements with \ #155

sqlalchemy-bot opened this issue Nov 12, 2010 · 2 comments
Labels
bug Something isn't working lexer low priority
Milestone

Comments

@sqlalchemy-bot
Copy link

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
Copy link
Author

Michael Bayer (@zzzeek) wrote:

6eea951

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working low priority lexer labels Nov 26, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.3.6 milestone Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lexer low priority
Projects
None yet
Development

No branches or pull requests

1 participant