Skip to content
Myr

TemplateSyntaxError can be pickled

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

authored by Andrew Rabert · committed by David Lord · parent 715f357 · Browse files · 3 files+16 added−0 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+16 added−0 removed

  • tests:+7 added−0 removed
  • other:+9 added−0 removed

3 files+16 added−0 removed

modified:jinja2/exceptions.py+7 added
139 unmodified lines
140 lines.append(' ' + line.strip())141142 return u'\n'.join(lines)143144 def __reduce__(self):145 # https://bugs.python.org/issue1692335 Exceptions that take146 # multiple required arguments have problems with pickling.147 # Without this, raises TypeError: __init__() missing 1 required148 # positional argument: 'lineno'149 return self.__class__, (self.message, self.lineno, self.name, self.filename)150151152class TemplateAssertionError(TemplateSyntaxError):153 """Like a template syntax error, but covers cases where something in the154 template caused an error at compile time that wasn't necessarily caused155 by a syntax error. However it's a direct subclass of
24 unmodified lines
modified:tests/test_debug.py+7 added
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import pytest1213import pickle14import re15import sys16from traceback import format_exception17
53 unmodified lines
71 raise TemplateSyntaxError\('wtf', 42\)72(jinja2\.exceptions\.)?TemplateSyntaxError: wtf73 line 42''')7475 def test_pickleable_syntax_error(self, fs_env):76 original = TemplateSyntaxError("bad template", 42, "test", "test.txt")77 unpickled = pickle.loads(pickle.dumps(original))78 assert str(original) == str(unpickled)79 assert original.name == unpickled.name8081 def test_include_syntax_error_source(self, filesystem_loader):82 e = Environment(loader=ChoiceLoader(83 [84 filesystem_loader,
26 unmodified lines
modified:CHANGES.rst+2 added
97 unmodified lines
98 ``extends``, ``import``, or ``include``), raises an99 ``UndefinedError`` consistently. ``select_template`` will show the100 undefined message in the list of attempts rather than the empty101 string. :issue:`1037`102- ``TemplateSyntaxError`` can be pickled. :pr:`1117`103104105Version 2.10.3106--------------107108Released 2019-10-04
627 unmodified lines