Fixes #1448: Revert Undefined.__contains__ to 2.x behaviour
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Joachim Jablon · committed by David Lord · parent 1891320 · 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
Provenance
- Commit
d5f49f5- Tree
25efb57- Author
Joachim Jablon <joachim.jablon@people-doc.com>- Committer
David Lord <davidism@gmail.com>- Parent
1891320
3 files changed+6 added−4 removed
modified:src/jinja2/runtime.py+2 added-1 removed
913 unmodified lines914 __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 lines1090 1091 __slots__ = ()1092 __iter__ = __str__ = __len__ = Undefined._fail_with_undefined_error1093 __eq__ = __ne__ = __bool__ = __hash__ = Undefined._fail_with_undefined_error1094+ __contains__ = Undefined._fail_with_undefined_error1095 1096 1097 # Remove slots attributes, after the metaclass is applied they are1098 # unneeded and contain wrong data for subclasses.6 unmodified linesmodified:tests/test_api.py+2 added-1 removed
314 unmodified lines315 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 != 4250 unmodified lines374 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 linesmodified:CHANGES.rst+2 added-2 removed
1 unmodified line2 3 Version 3.0.24 -------------5 6-Unreleased7-6 - 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`12 13 14 Version 3.0.115 -------------876 unmodified lines