From fcf9e3018d5e87f49e1f3f3d68ad4cc49382c0b9 Mon Sep 17 00:00:00 2001 From: Simon King Date: Sun, 29 Dec 2013 13:57:15 +0100 Subject: [PATCH] Trac 15278: Only graphs that use the static backend are identical with their copy --- src/sage/graphs/generic_graph.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index c75bf48af76..9dfb22b90f1 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -717,7 +717,8 @@ def __copy__(self, implementation='c_graph', data_structure=None, NOTE: - If the graph is immutable then the graph itself is returned, rather + If the graph uses :class:`~sage.graphs.base.static_sparse_backend.StaticSparseBackend` + and uses the _immutable flag, then ``self`` is returned, rather than a copy, unless one of the optional arguments is used. INPUT: @@ -815,6 +816,19 @@ def __copy__(self, implementation='c_graph', data_structure=None, sage: g is g.copy(data_structure='static_sparse') True + If a graph pretends to be immutable, but does not use the static sparse + backend, then the copy is not identic with the graph, even though it is + considered to be hashable:: + + sage: P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]), + linear_extension=True, facade = False) + sage: H = P.hasse_diagram() + sage: H._immutable = True + sage: hash(H) # random + -1843552882 + sage: copy(H) is H + False + """ if sparse != None: if data_structure != None: @@ -823,7 +837,8 @@ def __copy__(self, implementation='c_graph', data_structure=None, data_structure = "sparse" if sparse else "dense" if getattr(self, '_immutable', False): - if implementation=='c_graph' and (data_structure=='static_sparse' or data_structure is None): + from sage.graphs.base.static_sparse_backend import StaticSparseBackend + if isinstance(self._backend, StaticSparseBackend) and implementation=='c_graph' and (data_structure=='static_sparse' or data_structure is None): return self if data_structure is None: