]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Setting __sub__ equal to _fail_with_undefined_error so subtractions with 530/head
authorNick Garcia <Nick.Garcia@adp.com>
Thu, 7 Jan 2016 23:23:26 +0000 (15:23 -0800)
committerNick Garcia <Nick.Garcia@adp.com>
Thu, 7 Jan 2016 23:23:26 +0000 (15:23 -0800)
undefined variables will fail properly like other arithemtic operations.

jinja2/runtime.py
tests/test_api.py

index 685a12da068c4808f2dfcec64d68e581f47e26fe..3cc7aaa9ef7a188eca7b395a421eed37ea9ba93f 100644 (file)
@@ -498,7 +498,7 @@ class Undefined(object):
         __truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ = \
         __mod__ = __rmod__ = __pos__ = __neg__ = __call__ = \
         __getitem__ = __lt__ = __le__ = __gt__ = __ge__ = __int__ = \
-        __float__ = __complex__ = __pow__ = __rpow__ = \
+        __float__ = __complex__ = __pow__ = __rpow__ = __sub__ = \
         _fail_with_undefined_error
 
     def __eq__(self, other):
index 99d8dc1e13ea9994cbb3f24e18977ded074d5d03..5402698e364260a2b8d824fd45aa9e4838db987f 100644 (file)
@@ -244,6 +244,8 @@ class TestUndefined():
             == 'True'
         assert env.from_string('{{ foo.missing }}').render(foo=42) == ''
         assert env.from_string('{{ not missing }}').render() == 'True'
+        pytest.raises(UndefinedError,
+                      env.from_string('{{ missing - 1}}').render)
 
     def test_debug_undefined(self):
         env = Environment(undefined=DebugUndefined)