running into basic usability problems

10 views
Skip to first unread message

Istvan Albert

unread,
Nov 9, 2010, 11:45:23 AM11/9/10
to Mako Templates for Python
I was trying to switch to Mako but I ran into a very basic usability
problem that I can't figure out. Now I am starting to regret the
switch.

If I mistype a variable name I can't figure out what it is, all I get
is a UNDEFINED. Googling turns out some partial solutions that don't
actually work:

http://groups.google.com/group/mako-discuss/browse_thread/thread/ea2730abb499b6b2

The exceptions that are raised don't always point the at the right
error. Plus they are very hard to read to begin with.

NameErrors are so basic, common and ubiquitous, that not providing
support for finding out where they come from feels mind-boggling to
me. The situation is worse than for Django, that in turn also
implements an suboptimal choice of ignoring the missing names but at
least I can find out what is missing by looking at the output.

To put it into context, imagine trying to learn Python without a
proper NameError, and every time you mistyped a variable, module or
function name, you would get a mysterious something is "undefined".

Istvan


Michael Bayer

unread,
Nov 9, 2010, 12:29:53 PM11/9/10
to mako-d...@googlegroups.com

I apologize for your mind being boggled. The stack trace displayed when the error is thrown should illustrate what line of code caused the named error as well as the specific name. You should also be using one of the supplied error formatters so that the stack trace is formatted in terms of the original template, instead of the generated code. A similar condition in Python, which is ubiquitous, is the "NoneType has no attribute 'foo'" type of error, where similarly you don't get to see what variable is incorrectly None unless you look at the stack trace. The condition here is exactly analogous, rather than the NameError example you cite.

UNDEFINED is a singleton constant so that you can use "x is UNDEFINED" on it, so it doesn't know what name is being called upon (just like None). Its behavior is described at http://www.makotemplates.org/docs/runtime.html#runtime_context_variables .

We may provide an option in version 4 so that "is" no longer works but the UNDEFINED object would be per-usage and store the name.


Michael Bayer

unread,
Nov 9, 2010, 7:46:27 PM11/9/10
to mako-d...@googlegroups.com

On Nov 9, 2010, at 11:45 AM, Istvan Albert wrote:


r9bd80bb55e97 includes a new flag on Template and TemplateLookup, strict_undefined=True. Set this flag and UNDEFINED is no longer used. Any name that is missing will raise an immediate NameError upon template render. This will be in 0.3.6 and you can get it now at http://hg.makotemplates.org/mako/archive/9bd80bb55e97.tar.gz . Please let me know if you have any issues with it, thanks.


>
> Istvan
>
>
> --
> You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
> 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.
>

Istvan Albert

unread,
Nov 10, 2010, 1:15:13 PM11/10/10
to Mako Templates for Python


On Nov 9, 7:46 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:

> r9bd80bb55e97 includes a new flag on Template and TemplateLookup, strict_undefined=True.  Set this flag and UNDEFINED is no longer used.  Any name that is missing will raise an immediate NameError upon template render.   This will be in 0.3.6 and you can get it now athttp://hg.makotemplates.org/mako/archive/9bd80bb55e97.tar.gz.  Please let me know if you have any issues with it, thanks.

Whoa! That's such a nice fix! It works great.

Thanks for the quick response, much appreciated.

(my apologies for the rant, I was a bit impatient, I spent one too
many hours debugging a large template. I apologize if I came across
as rude)

best regards,

Istvan

Michael Bayer

unread,
Nov 10, 2010, 1:40:33 PM11/10/10
to mako-d...@googlegroups.com

I'm noticing lately i have the urge to be a little sarcastic when theres a little bit of hyperbole coming my way, so I hope our mutual smarminess cancelled itself out !

anyway i made some more changes to the parser to accommodate some new issues that change raises so you should get the latest tip.

>
> best regards,

Reply all
Reply to author
Forward
0 new messages