-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit 31089d4
Release Manager
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):
File tree
Expand file treeCollapse file tree
1 file changed
+2
-1
lines changedOpen diff view settings
Filter options
- src/sage/interfaces
Expand file treeCollapse file tree
1 file changed
+2
-1
lines changedOpen diff view settings
Collapse file
src/sage/interfaces/fricas.py
Copy file name to clipboardExpand all lines: src/sage/interfaces/fricas.py+2-1Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
| 292 | + | |
| 293 | + | |
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
| |||
0 commit comments