Skip to content
Myr

Merge pull request #1455 from ewjoachim/undefined-contains-1204

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

Only StrictUndefined.__contains__ raises error

authored by David Lord · committed by GitHub · parents 1891320, d5f49f5 · Browse files · 3 files+6 added−4 removed
This commit

State

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

Diff stats

3 files+6 added−4 removed

  • tests:+2 added−1 removed
  • other:+4 added−3 removed

3 files+6 added−4 removed

modified:src/jinja2/runtime.py+2 added-1 removed
913 unmodified lines
914 __truediv__ = __rtruediv__ = _fail_with_undefined_error915 __floordiv__ = __rfloordiv__ = _fail_with_undefined_error916 __mod__ = __rmod__ = _fail_with_undefined_error917 __pos__ = __neg__ = _fail_with_undefined_error918 __call__ = __getitem__ = __contains__ = _fail_with_undefined_error918 __call__ = __getitem__ = _fail_with_undefined_error919 __lt__ = __le__ = __gt__ = __ge__ = _fail_with_undefined_error920 __int__ = __float__ = __complex__ = _fail_with_undefined_error921 __pow__ = __rpow__ = _fail_with_undefined_error922
167 unmodified lines
10901091 __slots__ = ()1092 __iter__ = __str__ = __len__ = Undefined._fail_with_undefined_error1093 __eq__ = __ne__ = __bool__ = __hash__ = Undefined._fail_with_undefined_error1094 __contains__ = Undefined._fail_with_undefined_error109510961097# Remove slots attributes, after the metaclass is applied they are1098# unneeded and contain wrong data for subclasses.
6 unmodified lines
modified:tests/test_api.py+2 added-1 removed
314 unmodified lines
315 assert env.from_string("{{ missing is not defined }}").render() == "True"316 assert env.from_string("{{ foo.missing }}").render(foo=42) == ""317 assert env.from_string("{{ not missing }}").render() == "True"318 pytest.raises(UndefinedError, env.from_string("{{ missing - 1}}").render)319 pytest.raises(UndefinedError, env.from_string("{{ 'foo' in missing }}").render)319 assert env.from_string("{{ 'foo' in missing }}").render() == "False"320 und1 = Undefined(name="x")321 und2 = Undefined(name="y")322 assert und1 == und2323 assert und1 != 42
50 unmodified lines
374 env = Environment(undefined=StrictUndefined)375 pytest.raises(UndefinedError, env.from_string("{{ missing }}").render)376 pytest.raises(UndefinedError, env.from_string("{{ missing.attribute }}").render)377 pytest.raises(UndefinedError, env.from_string("{{ missing|list }}").render)378 pytest.raises(UndefinedError, env.from_string("{{ 'foo' in missing }}").render)379 assert env.from_string("{{ missing is not defined }}").render() == "True"380 pytest.raises(381 UndefinedError, env.from_string("{{ foo.missing }}").render, foo=42382 )
52 unmodified lines
modified:CHANGES.rst+2 added-2 removed
1 unmodified line
23Version 3.0.24-------------56Unreleased76- Fix a loop scoping bug that caused assignments in nested loops7 to still be referenced outside of it. :issue:`1427`8- Make ``compile_templates`` deterministic for filter and import9 names. :issue:`1452, 1453`10- Revert an unintended change that caused ``Undefined`` to act like11 ``StrictUndefined`` for the ``in`` operator. :issue:`1448`121314Version 3.0.115-------------
876 unmodified lines