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
@@ -45,8 +46,8 @@ def YangBaxterGraph(partition=None, root=None, operators=None):
4546
4647 OUTPUT: either:
4748
48- - :class:`YangBaxterGraph_partition` -- if partition is defined
49- - :class:`YangBaxterGraph_generic` -- if partition is ``None``
49+ - :class:`YangBaxterGraph_partition` -- if partition is defined
50+ - :class:`YangBaxterGraph_generic` -- if partition is ``None``
5051
5152 EXAMPLES:
5253
@@ -108,8 +109,7 @@ def YangBaxterGraph(partition=None, root=None, operators=None):
108109 """
109110 if partition is None :
110111 return YangBaxterGraph_generic (root = root , operators = operators )
111- else :
112- return YangBaxterGraph_partition (partition = Partition (partition ))
112+ return YangBaxterGraph_partition (partition = Partition (partition ))
113113
114114# *********** General class for Yang-Baxter Graphs ***********
115115
@@ -203,7 +203,7 @@ def _digraph(self):
203203 digraph .add_edge (u , v , l )
204204 return digraph
205205
206- def __hash__ (self ):
206+ def __hash__ (self ) -> int :
207207 r"""
208208 TESTS::
209209
@@ -236,7 +236,7 @@ def __eq__(self, other) -> bool:
236236 sage: Y3.__eq__(Y2)
237237 False
238238 """
239- return type ( self ) is type ( other ) and self ._digraph == other ._digraph
239+ return isinstance ( other , YangBaxterGraph_generic ) and self ._digraph == other ._digraph
240240
241241 def __ne__ (self , other ) -> bool :
242242 r"""
@@ -311,7 +311,6 @@ def __copy__(self):
311311 sage: Y == B
312312 True
313313 """
314- from copy import copy
315314 Y = self .__class__ (self ._root , self ._operators )
316315 Y ._digraph = copy (self ._digraph )
317316 return Y
@@ -421,9 +420,7 @@ def vertices(self, sort=False) -> list:
421420 sage: Y.vertices(sort=True)
422421 [(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)]
423422 """
424- if sort :
425- return sorted (self )
426- return list (self )
423+ return sorted (self ) if sort else list (self )
427424
428425 def edges (self ):
429426 r"""
@@ -505,7 +502,6 @@ def relabel_vertices(self, v, relabel_operator, inplace=True):
505502 sage: Y.vertices(sort=True)
506503 [(1, 2, 3, 4), (2, 1, 3, 4), (2, 3, 1, 4)]
507504 """
508- from copy import copy
509505 relabelling = self .vertex_relabelling_dict (v , relabel_operator )
510506 Y = self if inplace else copy (self )
511507 Y ._root = relabelling [Y ._root ]
@@ -540,11 +536,7 @@ def relabel_edges(self, edge_dict, inplace=True):
540536 sage: Y.edges()
541537 [((0, 2, 1, 0), (2, 0, 1, 0), 17), ((2, 0, 1, 0), (2, 1, 0, 0), 27)]
542538 """
543- if inplace :
544- Y = self
545- else :
546- from copy import copy
547- Y = copy (self )
539+ Y = self if inplace else copy (self )
548540 digraph = Y ._digraph
549541 for u , v in digraph .edges (sort = False , labels = False ):
550542 digraph .set_edge_label (u , v , edge_dict [u , v ])
@@ -614,7 +606,6 @@ def __copy__(self):
614606 sage: Y == B
615607 True
616608 """
617- from copy import copy
618609 Y = self .__class__ (self ._partition )
619610 Y ._digraph = copy (self ._digraph )
620611 return Y
@@ -634,7 +625,7 @@ def _digraph(self):
634625 [((0, 1, 0), (1, 0, 0), Swap positions 0 and 1)]
635626 """
636627 digraph = super ()._digraph
637- for ( u , v , op ) in digraph .edges (sort = True ):
628+ for u , v , op in digraph .edges ():
638629 digraph .set_edge_label (u , v , SwapOperator (op .position ()))
639630 return digraph
640631
@@ -754,11 +745,10 @@ def relabel_vertices(self, v, inplace=True):
754745 Y ._digraph .relabel (relabelling , inplace = inplace )
755746 Y ._vertex_ordering = Y ._digraph .vertices (sort = True )
756747 return
757- else :
758- from copy import copy
759- Y = copy (self )
760- Y ._root = relabelling [Y ._root ]
761- 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 )
762752
763753# ------------- Some Yang-Baxter operators ------------------
764754
@@ -777,7 +767,7 @@ def __init__(self, i):
777767 """
778768 self ._position = i
779769
780- def __hash__ (self ):
770+ def __hash__ (self ) -> int :
781771 r"""
782772 TESTS::
783773
@@ -925,9 +915,8 @@ def __call__(self, u):
925915 j = i + 1
926916 if u [i ] < u [j ]:
927917 v = list (u )
928- ( v [j ], v [i ]) = ( v [i ], v [j ])
918+ v [j ], v [i ] = v [i ], v [j ]
929919 if isinstance (u , Permutation ):
930920 return Permutation (v )
931921 return type (u )(v )
932- else :
933- return u
922+ return u
0 commit comments