You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's the description. When identificators starting with else, elif, try, except,
finally, while, for, def and class are present inside template context, code generator
gets confused about indentions.
So the generated code looks like this:
Of course, prefixes and abbreviations can be used, but I think this is unmotivated
constrain. Especially when it is only about syntax test for variable name in Python.
Only few changes in regular expressions are needed inside '''mako.pygen.PythonPrinter.writeline''' and
'''mako.pygen.PythonPrinter._is_unindentor''', simply by writing this:
(base_regexp)[^\da-zA-Z_]+'''
Maybe, I've missed something, but the code seems to work now.
Here's (if you can say it) the patch from version which I currently use.
10c10,13
< from StringIO import StringIO
---
> try:
> from cStringIO import StringIO
> except ImportError:
> from StringIO import StringIO
105c108
< match = re.match(r"^\s*(if|try|elif|while|for)", line)
---
> match = re.match(r"^\s*(if|try|elif|while|for)[^\da-zA-Z_]+", line)
116c119
< m2 = re.match(r"^\s*(def|class|else|elif|except|finally)", line)
---
> m2 = re.match(r"^\s*(def|class|else|elif|except|finally)[^\da-zA-Z_]", line)
141c144
< match = re.match(r"^\s*(else|elif|except|finally)", line)
---
> match = re.match(r"^\s*(else|elif|except|finally)[^\da-zA-Z_]+", line)
I have a short fix for this in f636709, which resolves the failing test case I was able to create. But I don't know what tests fail for you since you didn't post any, so feel free to post those if this fix doesn't resolve the issue.
Migrated issue, originally created by Anonymous
Here's the description. When identificators starting with else, elif, try, except,
finally, while, for, def and class are present inside template context, code generator
gets confused about indentions.
So the generated code looks like this:
and
Of course, prefixes and abbreviations can be used, but I think this is unmotivated
constrain. Especially when it is only about syntax test for variable name in Python.
Only few changes in regular expressions are needed inside '''mako.pygen.PythonPrinter.writeline''' and
'''mako.pygen.PythonPrinter._is_unindentor''', simply by writing this:
Maybe, I've missed something, but the code seems to work now.
Here's (if you can say it) the patch from version which I currently use.
Attachments: pygen.py-1.patch
The text was updated successfully, but these errors were encountered: