Skip to content

Commit fd38365

Browse files
committed
make custom name attribute private to SageObject
1 parent d819017 commit fd38365

File tree

19 files changed

+94
-91
lines changed

19 files changed

+94
-91
lines changed

src/doc/en/thematic_tutorials/tutorial-objects-and-classes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ http://docs.python.org/library/ for a complete list. ::
298298
sage: el
299299
bla
300300
sage: el.__dict__
301-
{'_custom_name': 'bla', 'value': 42}
301+
{'_SageObject__custom_name': 'bla', 'value': 42}
302302

303303
Lots of Sage objects are not Python objects but compiled Cython
304304
objects. Python sees them as builtin objects and you do not have

src/sage/groups/perm_gps/permgroup_element.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
2222
cpdef PermutationGroupElement _generate_new_GAP(self, old)
2323
cpdef _gap_list(self)
2424
cpdef domain(self)
25-
cdef public _custom_name
25+
cdef public _SageObject__custom_name
2626
cpdef list _act_on_list_on_position(self, list x)
2727
cpdef ClonableIntArray _act_on_array_on_position(self, ClonableIntArray x)
2828
cpdef ETuple _act_on_etuple_on_position(self, ETuple x)

src/sage/interfaces/interface.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,8 @@ def __repr__(self):
11691169
s = cr
11701170
else:
11711171
s = self._repr_()
1172-
if self._name in s:
1173-
try:
1174-
s = s.replace(self._name, getattr(self, '_custom_name'))
1175-
except AttributeError:
1176-
pass
1172+
if self._name in s and self.get_custom_name() is not None:
1173+
s = s.replace(self._name, self.get_custom_name())
11771174
if cr:
11781175
self._cached_repr = s
11791176
return s

src/sage/interfaces/singular.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,8 @@ def _repr_(self):
14001400
"""
14011401
s = super(SingularElement, self)._repr_()
14021402
if self._name in s:
1403-
if (not hasattr(self, "_custom_name")) and self.type() == 'matrix':
1404-
s = self.parent().eval('pmat(%s,20)'%(self.name()))
1403+
if self.get_custom_name() is None and self.type() == 'matrix':
1404+
s = self.parent().eval('pmat(%s,20)' % (self.name()))
14051405
return s
14061406

14071407
def __copy__(self):

src/sage/libs/gap/element.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ cdef class GapElement(RingElement):
720720
...
721721
AttributeError: 'some_name' does not define a GAP function
722722
"""
723-
if name in ('__dict__', '_getAttributeNames', '_custom_name', 'keys'):
723+
if name in ('__dict__', '_getAttributeNames', '_SageObject__custom_name', 'keys'):
724724
raise AttributeError('Python special name, not a GAP function.')
725725
try:
726726
proxy = make_GapElement_MethodProxy\

src/sage/matroids/basis_matroid.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ cdef class BasisMatroid(BasisExchangeMatroid):
11771177
11781178
"""
11791179
N = BasisMatroid(M=self)
1180-
N.rename(getattr(self, '_custom_name'))
1180+
N.rename(self.get_custom_name())
11811181
return N
11821182

11831183
def __deepcopy__(self, memo=None):
@@ -1201,7 +1201,7 @@ cdef class BasisMatroid(BasisExchangeMatroid):
12011201
if memo is None:
12021202
memo = {}
12031203
N = BasisMatroid(M=self)
1204-
N.rename(getattr(self, '_custom_name'))
1204+
N.rename(self.get_custom_name())
12051205
return N
12061206

12071207
def __reduce__(self):
@@ -1230,7 +1230,7 @@ cdef class BasisMatroid(BasisExchangeMatroid):
12301230
"""
12311231
import sage.matroids.unpickling
12321232
BB = bitset_pickle(self._bb)
1233-
data = (self._E, self._matroid_rank, getattr(self, '_custom_name'), BB)
1233+
data = (self._E, self._matroid_rank, self.get_custom_name(), BB)
12341234
version = 0
12351235
return sage.matroids.unpickling.unpickle_basis_matroid, (version, data)
12361236

src/sage/matroids/circuit_closures_matroid.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,7 @@ cdef class CircuitClosuresMatroid(Matroid):
513513
N._groundset = self._groundset
514514
N._circuit_closures = self._circuit_closures
515515
N._matroid_rank = self._matroid_rank
516-
if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy
517-
N.rename(getattr(self, '_custom_name'))
516+
N.rename(self.get_custom_name())
518517
return N
519518

520519
def __deepcopy__(self, memo=None):
@@ -539,8 +538,7 @@ cdef class CircuitClosuresMatroid(Matroid):
539538
from copy import deepcopy
540539
# Since matroids are immutable, N cannot reference itself in correct code, so no need to worry about the recursion.
541540
N = CircuitClosuresMatroid(groundset=deepcopy(self._groundset, memo), circuit_closures=deepcopy(self._circuit_closures, memo))
542-
if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy
543-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
541+
N.rename(deepcopy(self.get_custom_name(), memo))
544542
return N
545543

546544
def __reduce__(self):
@@ -570,7 +568,7 @@ cdef class CircuitClosuresMatroid(Matroid):
570568
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
571569
"""
572570
import sage.matroids.unpickling
573-
data = (self._groundset, self._circuit_closures, getattr(self, '_custom_name'))
571+
data = (self._groundset, self._circuit_closures, self.get_custom_name())
574572
version = 0
575573
return sage.matroids.unpickling.unpickle_circuit_closures_matroid, (version, data)
576574

src/sage/matroids/dual_matroid.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,7 @@ def __copy__(self):
519519
520520
"""
521521
N = DualMatroid(self._matroid)
522-
if getattr(self, '_custom_name') is not None:
523-
# because of name wrangling, this is not caught by the default copy
524-
N.rename(getattr(self, '_custom_name'))
522+
N.rename(self.get_custom_name())
525523
return N
526524

527525
def __deepcopy__(self, memo={}):
@@ -543,10 +541,7 @@ def __deepcopy__(self, memo={}):
543541
"""
544542
from copy import deepcopy
545543
N = DualMatroid(deepcopy(self._matroid, memo))
546-
if getattr(self, '_custom_name') is not None:
547-
# because of name wrangling, this is not caught by the
548-
# default deepcopy
549-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
544+
N.rename(deepcopy(self.get_custom_name(), memo))
550545
return N
551546

552547
def __reduce__(self):
@@ -575,6 +570,6 @@ def __reduce__(self):
575570
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}'
576571
"""
577572
import sage.matroids.unpickling
578-
data = (self._matroid, getattr(self, '_custom_name'))
573+
data = (self._matroid, self.get_custom_name())
579574
version = 0
580575
return sage.matroids.unpickling.unpickle_dual_matroid, (version, data)

src/sage/matroids/graphic_matroid.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ def __copy__(self):
481481
False
482482
"""
483483
N = GraphicMatroid(self._G)
484-
if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy
485-
N.rename(getattr(self, '_custom_name'))
484+
N.rename(self.get_custom_name())
486485
return N
487486

488487
def __deepcopy__(self, memo={}):
@@ -502,8 +501,7 @@ def __deepcopy__(self, memo={}):
502501
"""
503502
# The only real difference between this and __copy__() is the memo
504503
N = GraphicMatroid(deepcopy(self._G, memo))
505-
if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy
506-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
504+
N.rename(deepcopy(self.get_custom_name(), memo))
507505
return N
508506

509507
def __reduce__(self):
@@ -519,7 +517,7 @@ def __reduce__(self):
519517
Graphic matroid of rank 9 on 15 elements
520518
"""
521519
from .unpickling import unpickle_graphic_matroid
522-
data = (self._G, getattr(self, '_custom_name'))
520+
data = (self._G, self.get_custom_name())
523521
version = 0
524522
return unpickle_graphic_matroid, (version, data)
525523

src/sage/matroids/linear_matroid.pyx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,7 @@ cdef class LinearMatroid(BasisExchangeMatroid):
29092909
else:
29102910
rows, cols = self._current_rows_cols()
29112911
N = LinearMatroid(groundset=rows + cols, reduced_matrix=self._A)
2912-
N.rename(getattr(self, '_custom_name'))
2912+
N.rename(self.get_custom_name())
29132913
return N
29142914

29152915
def __deepcopy__(self, memo):
@@ -2930,7 +2930,7 @@ cdef class LinearMatroid(BasisExchangeMatroid):
29302930
else:
29312931
rows, cols = self._current_rows_cols()
29322932
N = LinearMatroid(groundset=deepcopy(rows + cols, memo), reduced_matrix=deepcopy(self._A, memo))
2933-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
2933+
N.rename(deepcopy(self.get_custom_name(), memo))
29342934
return N
29352935

29362936
def __reduce__(self):
@@ -2979,7 +2979,7 @@ cdef class LinearMatroid(BasisExchangeMatroid):
29792979
rows, cols = self._current_rows_cols()
29802980
gs = rows + cols
29812981
reduced = True
2982-
data = (A, gs, reduced, getattr(self, '_custom_name'))
2982+
data = (A, gs, reduced, self.get_custom_name())
29832983
return sage.matroids.unpickling.unpickle_linear_matroid, (version, data)
29842984

29852985
# Binary matroid
@@ -3964,7 +3964,7 @@ cdef class BinaryMatroid(LinearMatroid):
39643964
for e in self.basis():
39653965
basis[self._prow[self._idx[e]]] = e
39663966
N = BinaryMatroid(groundset=self._E, matrix=self._A, basis=basis)
3967-
N.rename(getattr(self, '_custom_name'))
3967+
N.rename(self.get_custom_name())
39683968
return N
39693969

39703970
def __deepcopy__(self, memo):
@@ -3989,7 +3989,7 @@ cdef class BinaryMatroid(LinearMatroid):
39893989
for e in self.basis():
39903990
basis[self._prow[self._idx[e]]] = e
39913991
N = BinaryMatroid(groundset=deepcopy(self._E, memo), matrix=deepcopy(self._A, memo), basis=deepcopy(basis, memo))
3992-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
3992+
N.rename(deepcopy(self.get_custom_name(), memo))
39933993
return N
39943994

39953995
def __reduce__(self):
@@ -4047,7 +4047,7 @@ cdef class BinaryMatroid(LinearMatroid):
40474047
A = self._A
40484048
# current basis ordered so matrix cols form identity matrix:
40494049
basis = self._current_rows_cols()[0]
4050-
data = (A, gs, basis, getattr(self, '_custom_name'))
4050+
data = (A, gs, basis, self.get_custom_name())
40514051
return sage.matroids.unpickling.unpickle_binary_matroid, (version, data)
40524052

40534053
cdef class TernaryMatroid(LinearMatroid):
@@ -4858,7 +4858,7 @@ cdef class TernaryMatroid(LinearMatroid):
48584858
for e in self.basis():
48594859
basis[self._prow[self._idx[e]]] = e
48604860
N = TernaryMatroid(groundset=self._E, matrix=self._A, basis=basis)
4861-
N.rename(getattr(self, '_custom_name'))
4861+
N.rename(self.get_custom_name())
48624862
return N
48634863

48644864
def __deepcopy__(self, memo):
@@ -4883,7 +4883,7 @@ cdef class TernaryMatroid(LinearMatroid):
48834883
for e in self.basis():
48844884
basis[self._prow[self._idx[e]]] = e
48854885
N = TernaryMatroid(groundset=deepcopy(self._E, memo), matrix=deepcopy(self._A, memo), basis=deepcopy(basis, memo))
4886-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
4886+
N.rename(deepcopy(self.get_custom_name(), memo))
48874887
return N
48884888

48894889
def __reduce__(self):
@@ -4945,7 +4945,7 @@ cdef class TernaryMatroid(LinearMatroid):
49454945
A = self._A
49464946
# current basis ordered so matrix cols form identity matrix:
49474947
basis = self._current_rows_cols()[0]
4948-
data = (A, gs, basis, getattr(self, '_custom_name'))
4948+
data = (A, gs, basis, self.get_custom_name())
49494949
return sage.matroids.unpickling.unpickle_ternary_matroid, (version, data)
49504950

49514951
# Quaternary Matroids
@@ -5589,7 +5589,7 @@ cdef class QuaternaryMatroid(LinearMatroid):
55895589
for e in self.basis():
55905590
basis[self._prow[self._idx[e]]] = e
55915591
N = QuaternaryMatroid(groundset=self._E, matrix=self._A, basis=basis)
5592-
N.rename(getattr(self, '_custom_name'))
5592+
N.rename(self.get_custom_name())
55935593
return N
55945594

55955595
def __deepcopy__(self, memo):
@@ -5614,7 +5614,7 @@ cdef class QuaternaryMatroid(LinearMatroid):
56145614
for e in self.basis():
56155615
basis[self._prow[self._idx[e]]] = e
56165616
N = QuaternaryMatroid(groundset=deepcopy(self._E, memo), matrix=deepcopy(self._A, memo), basis=deepcopy(basis, memo))
5617-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
5617+
N.rename(deepcopy(self.get_custom_name(), memo))
56185618
return N
56195619

56205620
def __reduce__(self):
@@ -5672,7 +5672,7 @@ cdef class QuaternaryMatroid(LinearMatroid):
56725672
A = self._A
56735673
# current basis ordered so matrix cols form identity matrix:
56745674
basis = self._current_rows_cols()[0]
5675-
data = (A, gs, basis, getattr(self, '_custom_name'))
5675+
data = (A, gs, basis, self.get_custom_name())
56765676
return sage.matroids.unpickling.unpickle_quaternary_matroid, (version, data)
56775677

56785678
# Regular Matroids
@@ -6524,7 +6524,7 @@ cdef class RegularMatroid(LinearMatroid):
65246524
else:
65256525
rows, cols = self._current_rows_cols()
65266526
N = RegularMatroid(groundset=rows + cols, reduced_matrix=self._A)
6527-
N.rename(getattr(self, '_custom_name'))
6527+
N.rename(self.get_custom_name())
65286528
return N
65296529

65306530
def __deepcopy__(self, memo):
@@ -6544,7 +6544,7 @@ cdef class RegularMatroid(LinearMatroid):
65446544
else:
65456545
rows, cols = self._current_rows_cols()
65466546
N = RegularMatroid(groundset=deepcopy(rows + cols, memo), reduced_matrix=deepcopy(self._A, memo))
6547-
N.rename(deepcopy(getattr(self, '_custom_name'), memo))
6547+
N.rename(deepcopy(self.get_custom_name(), memo))
65486548
return N
65496549

65506550
def __reduce__(self):
@@ -6593,5 +6593,5 @@ cdef class RegularMatroid(LinearMatroid):
65936593
rows, cols = self._current_rows_cols()
65946594
gs = rows + cols
65956595
reduced = True
6596-
data = (A, gs, reduced, getattr(self, '_custom_name'))
6596+
data = (A, gs, reduced, self.get_custom_name())
65976597
return sage.matroids.unpickling.unpickle_regular_matroid, (version, data)

0 commit comments

Comments
 (0)