Issues

Issue #140 new

inconsistent behavior of filter pulling from context based on name

Mike Bayer
repo owner created an issue

this is related to #3 but seems different

  1. !python from mako.template import Template

x = Template(""" X: ${"asdf" | h.foo} """)

y = Template(""" Y: ${"asdf" | z.foo} """)

z = Template(""" Z: ${h} ${"asdf" | h.foo} """)

class h(object): foo = str

try: print x.render(h=h) except NameError, e: print e

print y.render(z=h) print z.render(h=h)

Comments (3)

  1. Mike Bayer reporter
    • changed milestone to 0.4

    the issue is because we consider the identifier 'h' to be declared at parse tree time. the `undeclared_identifiers` method of `Expression` and `DefTag` would need to be modified to walk through the parsed filter expression fully, and only pop out single, undotted identifiers that are present in DEFAULT_ESCAPES instead of everything in DEFAULT_ESCAPES - however, that still wouldn't solve this:

    ${'foo' | h, h.strip}

    I suppose the fix to *that* would be, because h.strip is there, its undeclared. "h" as a builtin would basically be blown away from that.

    the other solution is, don't allow "h.strip" in there. if we work with the regexp in codegen create_filter_callable(), we could have that. It's probably preferable.

  2. Log in to comment