-
-
Notifications
You must be signed in to change notification settings - Fork 660
Description
Most Sage objects are immutable. Nevertheless, copy
and deepcopy
make copies (through pickling/unpickling) for them because we have not provided the classes with __copy__
methods (which should just return the object) and __deepcopy__
methods (which in many cases should just return the object).
sage: a = 0
sage: copy(a) is a
False
Another symptom (from the original ticket description): Copying of (immutable!) LazyFamily
objects only works for families that can be pickled:
sage: def unpicklableFamily():
... x = 10
... return LazyFamily([1,2,3], lambda n: x*n)
sage: f = unpicklableFamily()
sage: copy(f)
Traceback (most recent call last):
...
ValueError: Cannot pickle code objects from closures
The case of __deepcopy__
of immutable container-like objects (like Family
or Sequence
) is a bit trickier: Is immutability intended to imply that the elements are immutable too? In this ticket, we make no such assumption.
Tickets:
- trivial __copy__ and __deepcopy__ methods for number types #32454 trivial
__copy__
and__deepcopy__
methods for number types - trivial __copy__ and __deepcopy__ methods for number field elements #32478 trivial
__copy__
and__deepcopy__
methods for number field elements - trivial __copy__ and __deepcopy__ methods for symbolic expressions and functions #32480 trivial
__copy__
and__deepcopy__
methods for symbolic expressions and functions - trivial __copy__ and __deepcopy__ methods for Family and Set #32462 trivial
__copy__
and__deepcopy__
methods forFamily
andSet
- __copy__ methods for all classes that define "copy" methods (outside of sage.tensor, sage.manifolds) #32453
__copy__
methods for all classes that definecopy
methods - sage.tensor, sage.manifolds: __copy__, __deepcopy__ methods for all classes that define "copy" methods #32476
sage.tensor
,sage.manifolds
:__copy__
,__deepcopy__
methods for all classes that definecopy
methods - copy(CombinatorialFreeModule.Element) broken by #22632 #23075
copy(CombinatorialFreeModule.Element)
broken by Cythonize CombinatorialFreeModuleElement #22632 - Fix some more deepcopy/caching issues in the quadratic forms code (followup to #5403) #5417 Fix some more deepcopy/caching issues in the quadratic forms code
Related: - sage.structure.mutability: Add global is_mutable, is_immutable functions #30387
Depends on #32454
CC: @tscrim @mjungmath @nbruin @kwankyu @williamstein @mwageringel @kcrisman
Component: pickling
Keywords: LazyFamily, copy, pickle
Author: Matthias Koeppe
Branch/Commit: u/mkoeppe/__copy___and___deepcopy___methods_for_all_immutable_sage_objects @ 2bd01ae
Issue created by migration from https://trac.sagemath.org/ticket/13811