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: