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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cocolato
Copy link
Contributor

Fixes: #140 and #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.

args = self.compiler.default_filters + args
for e in args:
# if filter given as a function, get just the identifier portion
if e == "n":
if e in (DEFAULT_ESCAPED_N, "n"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here fix the problem mentioned in issue 100.

@cocolato
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inconsistent behavior of filter pulling from context based on name
2 participants