mako icon indicating copy to clipboard operation
mako copied to clipboard

Support passing custom filters with the same name as built-in flags

Open cocolato opened this issue 1 year ago • 1 comments

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.

cocolato avatar Dec 12 '24 13:12 cocolato

Hi, maintainer. This change submission may not need to be released right now. I can try to fix some other existing issues of Mako.

cocolato avatar Dec 12 '24 13:12 cocolato