Skip to content
Myr

Undefineds give better hints for `None` objects now.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 2e3c9c7 · Browse files · 2 files+10 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−3 removed

  • other:+10 added−3 removed

2 files+10 added−3 removed

modified:jinja2/testsuite/api.py+7 added
205 unmodified lines
206 def test_indexing_gives_undefined(self):207 t = Template("{{ var[42].foo }}")208 assert_raises(UndefinedError, t.render, var=0)209210 def test_none_gives_propert_error(self):211 try:212 Undefined(None).split()213 except UndefinedError, e:214 assert e.message == 'None is not defined'215 else:216 assert False, 'expected exception'217218219def suite():220 suite = unittest.TestSuite()
4 unmodified lines
modified:jinja2/runtime.py+3 added-3 removed
420 unmodified lines
421 """422 __slots__ = ('_undefined_hint', '_undefined_obj', '_undefined_name',423 '_undefined_exception')424425 def __init__(self, hint=None, obj=None, name=None, exc=UndefinedError):425 def __init__(self, hint=None, obj=missing, name=None, exc=UndefinedError):426 self._undefined_hint = hint427 self._undefined_obj = obj428 self._undefined_name = name429 self._undefined_exception = exc
3 unmodified lines
433 """Regular callback function for undefined objects that raises an434 `UndefinedError` on call.435 """436 if self._undefined_hint is None:437 if self._undefined_obj is None:437 if self._undefined_obj is missing:438 hint = '%r is undefined' % self._undefined_name439 elif not isinstance(self._undefined_name, basestring):440 hint = '%r object has no element %r' % (441 self._undefined_obj.__class__.__name__,
55 unmodified lines
497 __slots__ = ()498499 def __unicode__(self):500 if self._undefined_hint is None:501 if self._undefined_obj is None:501 if self._undefined_obj is missing:502 return u'{{ %s }}' % self._undefined_name503 return '{{ no such element: %s[%r] }}' % (504 self._undefined_obj.__class__.__name__,505 self._undefined_name
31 unmodified lines