__slots__ = ('_undefined_hint', '_undefined_obj', '_undefined_name',
'_undefined_exception')
- def __init__(self, hint=None, obj=None, name=None, exc=UndefinedError):
+ def __init__(self, hint=None, obj=missing, name=None, exc=UndefinedError):
self._undefined_hint = hint
self._undefined_obj = obj
self._undefined_name = name
`UndefinedError` on call.
"""
if self._undefined_hint is None:
- if self._undefined_obj is None:
+ if self._undefined_obj is missing:
hint = '%r is undefined' % self._undefined_name
elif not isinstance(self._undefined_name, basestring):
hint = '%r object has no element %r' % (
def __unicode__(self):
if self._undefined_hint is None:
- if self._undefined_obj is None:
+ if self._undefined_obj is missing:
return u'{{ %s }}' % self._undefined_name
return '{{ no such element: %s[%r] }}' % (
self._undefined_obj.__class__.__name__,
t = Template("{{ var[42].foo }}")
assert_raises(UndefinedError, t.render, var=0)
+ def test_none_gives_propert_error(self):
+ try:
+ Undefined(None).split()
+ except UndefinedError, e:
+ assert e.message == 'None is not defined'
+ else:
+ assert False, 'expected exception'
def suite():