Skip to content

Commit 31089d4

Browse files
author
Release Manager
committed
gh-40570: Fix fricas doctest pickling <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> Fix FriCAS doctest pickling failures Problem: Doctests in sage.interfaces.fricas were failing with TypeError: cannot pickle 'sage.misc.lazy_import.LazyImport' object when testing ```fricas == loads(dumps(fricas))```. ``` sage: fricas == loads(dumps(fricas)) ------------------------------------------------------------------------ --- TypeError Traceback (most recent call last) File ~/sage/src/sage/misc/persist.pyx:338, in sage.misc.persist.dumps() 337 type_obj = type((<LazyImport>obj).get_object()) --> 338 ans = type_obj.dumps(obj, compress) 339 except (AttributeError, RuntimeError, TypeError): File ~/sage/src/sage/structure/sage_object.pyx:508, in sage.structure.sage_object.SageObject.dumps() 507 --> 508 return _base_dumps(self, compress=compress) 509 File ~/sage/src/sage/misc/persist.pyx:306, in sage.misc.persist._base_dumps() 305 global already_pickled --> 306 gherkin = SagePickler.dumps(obj) 307 already_pickled = {} File ~/sage/src/sage/misc/persist.pyx:830, in sage.misc.persist.SagePickler.dumps() 829 pickler = cls(buf, **kwargs) --> 830 pickler.dump(obj) 831 already_pickled = {} TypeError: cannot pickle 'sage.misc.lazy_import.LazyImport' object During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) Cell In[1], line 1 ----> 1 fricas == loads(dumps(fricas)) File ~/sage/src/sage/misc/persist.pyx:340, in sage.misc.persist.dumps() 338 ans = type_obj.dumps(obj, compress) 339 except (AttributeError, RuntimeError, TypeError): --> 340 ans = _base_dumps(obj, compress=compress) 341 already_pickled = {} 342 return ans File ~/sage/src/sage/misc/persist.pyx:306, in sage.misc.persist._base_dumps() 304 305 global already_pickled --> 306 gherkin = SagePickler.dumps(obj) 307 already_pickled = {} 308 File ~/sage/src/sage/misc/persist.pyx:830, in sage.misc.persist.SagePickler.dumps() 828 buf = io.BytesIO() 829 pickler = cls(buf, **kwargs) --> 830 pickler.dump(obj) 831 already_pickled = {} 832 return buf.getvalue() TypeError: cannot pickle 'sage.misc.lazy_import.LazyImport' object ``` Solution: Replace the problematic equality test with isinstance(loads(dumps(a)), FriCAS) using a fresh FriCAS instance instead of the global fricas object, which contains unpicklable lazy imports. Changes: Modified doctests in ```FriCAS.__init__ ``` and ```FriCAS._quit_string``` methods Preserves serialization testing while avoiding LazyImport pickling issues ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40570 Reported by: Chenxin Zhong Reviewer(s):
2 parents 44c09ad + e44838f commit 31089d4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/sage/interfaces/fricas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ def __init__(self, name='fricas', command=None,
289289
290290
TESTS::
291291
292-
sage: fricas == loads(dumps(fricas))
292+
sage: a = FriCAS()
293+
sage: isinstance(loads(dumps(a)), FriCAS)
293294
True
294295
295296
Check that :issue:`25174` is fixed::

0 commit comments

Comments
 (0)