Skip to content

Commit

Permalink
Trac #23075: copy(CombinatorialFreeModule.Element) broken by #22632
Browse files Browse the repository at this point in the history
The following problem showed up with 8.0.beta8: the copy of an
IndexedFreeModuleElement seems to be not functional:
{{{
#!sage
sage: F=CombinatorialFreeModule(ZZ,ZZ)
sage: a=F.an_element() ; a
3*B[-1] + B[0] + 3*B[1]
sage: copy(a)
<repr(<sage.combinat.free_module.CombinatorialFreeModule_with_category.e
lement_class at 0x7f5d735e7808>) failed: AttributeError: 'NoneType'
object has no attribute 'items'>
sage: type(copy(a)._monomial_coefficients)
<type 'NoneType'>
}}}

Part of Meta-ticket #13811: Support Python's `__copy__` / `__deepcopy__`
protocol

URL: https://trac.sagemath.org/23075
Reported by: cnassau
Ticket author(s): Travis Scrimshaw
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Aug 29, 2022
2 parents 163f715 + ac1bf2c commit 894a296
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/sage/modules/with_basis/indexed_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ An element in an indexed free module
AUTHORS:
- Travis Scrimshaw (03-2017): Moved code from :mod:`sage.combinat.free_module`.
- Travis Scrimshaw (29-08-2022): Implemented ``copy`` as the identity map.
"""

#*****************************************************************************
# Copyright (C) 2017 Travis Scrimshaw <tcscrims at gmail.com>
# Copyright (C) 2017, 2022 Travis Scrimshaw <tcscrims at gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -180,6 +181,32 @@ cdef class IndexedFreeModuleElement(ModuleElement):
for k, v in state[1].iteritems():
setattr(self, k, v)
def __copy__(self):
r"""
Return ``self`` since ``self`` is immutable.
EXAMPLES::
sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: x = F.an_element()
sage: copy(x) is x
True
"""
return self
def __deepcopy__(self, memo=None):
r"""
Return ``self`` since ``self`` is immutable.
EXAMPLES::
sage: F = CombinatorialFreeModule(QQ, ['a','b','c'])
sage: x = F.an_element()
sage: deepcopy(x) is x
True
"""
return self
cpdef dict monomial_coefficients(self, bint copy=True):
"""
Return the internal dictionary which has the combinatorial objects
Expand Down

0 comments on commit 894a296

Please sign in to comment.