1. Michael Bayer
  2. mako

Issues

Issue #192 resolved

variable tracking for assignment inside of def

Michael Bayer
repo owner created an issue

from mako.template import Template t = Template( """ <% def foo(): s = 1 %>

""".strip(), strict_undefined=True, ) t.render()

would rise "NameError: 's' is not defined"

Comments (4)

  1. Michael Bayer reporter

    updated version generalizes names located within defs and fixes it for 2.4 as well.

    new test:

    t = Template( """ <% def foo(): s = 1 def bar(): t = s %>

    """.strip(), strict_undefined=True, )

    t.render()

  2. Michael Bayer reporter

    and more:

    t = Template( """ <% def foo(): class Bat(object): pass Bat %>

    """.strip(), strict_undefined=True, )

    1. should pass t.render()

    t = Template( """ <% def foo(): class Bat(object): pass Bat %>

    ${Bat}

    """.strip(), strict_undefined=True, )

    1. should pass t.render(Bat='adsf')
    1. should raise t.render()

    however, make sure we distill these into test_ast.py as more test_locate_identifiers tests.

  3. Log in to comment