1515#
1616# https://www.gnu.org/licenses/
1717# ****************************************************************************
18+ from copy import copy
1819
1920from sage .graphs .digraph import DiGraph
2021from sage .structure .sage_object import SageObject
@@ -310,7 +311,6 @@ def __copy__(self):
310311 sage: Y == B
311312 True
312313 """
313- from copy import copy
314314 Y = self .__class__ (self ._root , self ._operators )
315315 Y ._digraph = copy (self ._digraph )
316316 return Y
@@ -420,9 +420,7 @@ def vertices(self, sort=False) -> list:
420420 sage: Y.vertices(sort=True)
421421 [(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)]
422422 """
423- if sort :
424- return sorted (self )
425- return list (self )
423+ return sorted (self ) if sort else list (self )
426424
427425 def edges (self ):
428426 r"""
@@ -504,7 +502,6 @@ def relabel_vertices(self, v, relabel_operator, inplace=True):
504502 sage: Y.vertices(sort=True)
505503 [(1, 2, 3, 4), (2, 1, 3, 4), (2, 3, 1, 4)]
506504 """
507- from copy import copy
508505 relabelling = self .vertex_relabelling_dict (v , relabel_operator )
509506 Y = self if inplace else copy (self )
510507 Y ._root = relabelling [Y ._root ]
@@ -539,11 +536,7 @@ def relabel_edges(self, edge_dict, inplace=True):
539536 sage: Y.edges()
540537 [((0, 2, 1, 0), (2, 0, 1, 0), 17), ((2, 0, 1, 0), (2, 1, 0, 0), 27)]
541538 """
542- if inplace :
543- Y = self
544- else :
545- from copy import copy
546- Y = copy (self )
539+ Y = self if inplace else copy (self )
547540 digraph = Y ._digraph
548541 for u , v in digraph .edges (sort = False , labels = False ):
549542 digraph .set_edge_label (u , v , edge_dict [u , v ])
@@ -613,7 +606,6 @@ def __copy__(self):
613606 sage: Y == B
614607 True
615608 """
616- from copy import copy
617609 Y = self .__class__ (self ._partition )
618610 Y ._digraph = copy (self ._digraph )
619611 return Y
@@ -633,7 +625,7 @@ def _digraph(self):
633625 [((0, 1, 0), (1, 0, 0), Swap positions 0 and 1)]
634626 """
635627 digraph = super ()._digraph
636- for u , v , op in digraph .edges (sort = True ):
628+ for u , v , op in digraph .edges ():
637629 digraph .set_edge_label (u , v , SwapOperator (op .position ()))
638630 return digraph
639631
@@ -753,11 +745,10 @@ def relabel_vertices(self, v, inplace=True):
753745 Y ._digraph .relabel (relabelling , inplace = inplace )
754746 Y ._vertex_ordering = Y ._digraph .vertices (sort = True )
755747 return
756- else :
757- from copy import copy
758- Y = copy (self )
759- Y ._root = relabelling [Y ._root ]
760- return Y ._digraph .relabel (relabelling , inplace = inplace )
748+
749+ Y = copy (self )
750+ Y ._root = relabelling [Y ._root ]
751+ return Y ._digraph .relabel (relabelling , inplace = inplace )
761752
762753# ------------- Some Yang-Baxter operators ------------------
763754
@@ -924,9 +915,8 @@ def __call__(self, u):
924915 j = i + 1
925916 if u [i ] < u [j ]:
926917 v = list (u )
927- ( v [j ], v [i ]) = (v [i ], v [j ])
918+ v [j ], v [i ] = (v [i ], v [j ])
928919 if isinstance (u , Permutation ):
929920 return Permutation (v )
930921 return type (u )(v )
931- else :
932- return u
922+ return u
0 commit comments