mako
mako copied to clipboard
Support passing custom filters with the same name as built-in flags
Fixes: https://github.com/sqlalchemy/mako/issues/140 and https://github.com/sqlalchemy/mako/issues/415
During the lexical analysis phase, add an additional prefix for undeclared identifiers that have the same name as built-in flags, and determine the final filter to be used during the code generation phase based on the context provided by the user.
from mako.template import Template
x = Template("""
X:
${"asdf" | h.foo}
""")
class h(object):
foo = str
try:
print x.render(h=h)
except NameError, e:
print e
This code can now be rendered correctly.
Hi, maintainer. This change submission may not need to be released right now. I can try to fix some other existing issues of Mako.