1. Michael Bayer
  2. mako
  3. Issues


Issue #104 resolved

getattr not working on Namespace

created an issue

The method runtime.py:Namespace:__getattr__ raises RuntimeException when I think it should raise AttributeError.

This comes up when you try to do this in your template:

my_attr = getattr(my_namespace, my_attrname, None)

and there is no match for my_attrname. The expected behavior would be for None to be returned but instead RuntimeException does not get caught by getattr.

The use of AttributeError is mentioned here: http://docs.python.org/reference/datamodel.html#object.__getattr__

Index: lib/mako/runtime.py

--- lib/mako/runtime.py (revision 441) +++ lib/mako/runtime.py (working copy) @@ -260,7 +260,7 @@

if self.inherits is not None: return getattr(self.inherits, key) - raise exceptions.RuntimeException("Namespace '%s' has no member '%s'" % (self.name, key)) + raise AttributeError("Namespace '%s' has no member '%s'" % (self.name, key))

def supports_caller(func): """apply a caller_stack compatibility decorator to a plain Python function."""