Undefined.__contains__ raises UndefinedError

This commit is contained in:
David Parker 2020-05-09 13:04:28 -07:00 committed by David Lord
parent fd001b216a
commit 609bcb0831
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
3 changed files with 4 additions and 1 deletions

View File

@ -52,6 +52,8 @@ Unreleased
indent by. :pr:`1167`
- The parser understands hex, octal, and binary integer literals.
:issue:`1170`
- ``Undefined.__contains__`` (``in``) raises an ``UndefinedError``
instead of a ``TypeError``. :issue:`1198`
Version 2.11.3

View File

@ -755,7 +755,7 @@ class Undefined:
__floordiv__ = __rfloordiv__ = _fail_with_undefined_error
__mod__ = __rmod__ = _fail_with_undefined_error
__pos__ = __neg__ = _fail_with_undefined_error
__call__ = __getitem__ = _fail_with_undefined_error
__call__ = __getitem__ = __contains__ = _fail_with_undefined_error
__lt__ = __le__ = __gt__ = __ge__ = _fail_with_undefined_error
__int__ = __float__ = __complex__ = _fail_with_undefined_error
__pow__ = __rpow__ = _fail_with_undefined_error

View File

@ -317,6 +317,7 @@ class TestUndefined:
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)
pytest.raises(UndefinedError, env.from_string("{{ 'foo' in missing }}").render)
und1 = Undefined(name="x")
und2 = Undefined(name="y")
assert und1 == und2