Skip to content

Commit

Permalink
Merge pull request sympy#20470 from oscarbenjamin/pr_eric_17
Browse files Browse the repository at this point in the history
Fix pickling of print functions (1.7 branch)
  • Loading branch information
oscarbenjamin authored Nov 22, 2020
2 parents 4c8358d + c1c2c93 commit 56f88ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sympy/printing/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ def __init__(self, f, print_cls: Type[Printer]):
self.__print_cls = print_cls
update_wrapper(self, f)

def __reduce__(self):
# Since this is used as a decorator, it replaces the original function.
# The default pickling will try to pickle self.__wrapped__ and fail
# because the wrapped function can't be retrieved by name.
return self.__wrapped__.__qualname__

def __repr__(self) -> str:
return repr(self.__wrapped__) # type:ignore

Expand Down
5 changes: 5 additions & 0 deletions sympy/printing/tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2702,3 +2702,8 @@ def test_global_settings():
# check we really did undo it
assert inspect.signature(latex).parameters['imaginary_unit'].default == 'i'
assert latex(I) == 'i'

def test_pickleable():
# this tests that the _PrintFunction instance is pickleable
import pickle
assert pickle.loads(pickle.dumps(latex)) is latex

0 comments on commit 56f88ad

Please sign in to comment.