just another issue related to 'strict_undefined'

46 views
Skip to first unread message

George Xie

unread,
Nov 6, 2012, 3:12:39 PM11/6/12
to mako-d...@googlegroups.com
hi all

consider following template

from mako.template import Template

t = Template(
"""
<%
l = l

%>
""".strip(),
strict_undefined=True,
)
print t.render(l=l)


would raise "NameError: name 'l' is not defined"

mako thought 'l' is locally_declared, is this a bug or feature?
I think this is caused by scope rule simulation,
say that though 'l' actually in function scope of render_body, where 'l' could be get from render context,
but in fact it is in the logical global scope, which is mimicked by mako, therefore mako wont try to exact 'l' from context.

Michael Bayer

unread,
Nov 6, 2012, 4:17:03 PM11/6/12
to mako-d...@googlegroups.com
this is not valid Python, so I'm not sure what feature you'd be looking for here:

>>> l = 'hi'
>>> def foo():
...     l = l
... 
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
UnboundLocalError: local variable 'l' referenced before assignment
>>> 


--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mako-discuss/-/CNPrCGaY4coJ.
To post to this group, send email to mako-d...@googlegroups.com.
To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.

George Xie

unread,
Nov 6, 2012, 5:24:30 PM11/6/12
to mako-d...@googlegroups.com
okay, I get it.
Reply all
Reply to author
Forward
0 new messages