Skip to content

Commit

Permalink
sagemathgh-36462: using ruff for UP004, UP008, UP028
Browse files Browse the repository at this point in the history
    
this was scripted using

`ruff check --fix --select UP004,UP008,UP028 src/sage`

here is the link to `ruff` documentation:
https://docs.astral.sh/ruff/rules/

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#36462
Reported by: Frédéric Chapoton
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Oct 25, 2023
2 parents 9733c0e + e3ca71f commit 8c50663
Show file tree
Hide file tree
Showing 74 changed files with 117 additions and 163 deletions.
2 changes: 1 addition & 1 deletion src/sage/algebras/free_algebra_quotient.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from sage.structure.unique_representation import UniqueRepresentation


class FreeAlgebraQuotient(UniqueRepresentation, Algebra, object):
class FreeAlgebraQuotient(UniqueRepresentation, Algebra):
@staticmethod
def __classcall__(cls, A, mons, mats, names):
"""
Expand Down
6 changes: 2 additions & 4 deletions src/sage/categories/enumerated_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ def iterator_range(self, start=None, stop=None, step=None):
if stop is None:
if start is None:
if step is None:
for x in self:
yield x
yield from self
return
start = 0
elif start < 0:
Expand Down Expand Up @@ -793,8 +792,7 @@ def _iterator_from_list(self):
sage: [next(it), next(it), next(it)]
[1, 2, 3]
"""
for x in self.tuple():
yield x
yield from self.tuple()

def _iterator_from_next(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions src/sage/categories/finite_enumerated_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ def iterator_range(self, start=None, stop=None, step=None):
for j in range(stop):
yield next(it)
return
for x in self:
yield x
yield from self
return
if L is None:
L = self.tuple()
Expand Down
3 changes: 1 addition & 2 deletions src/sage/categories/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def __iter__(self):
from sage.combinat.posets.posets import FinitePosets_n
n = 0
while True:
for P in FinitePosets_n(n):
yield P
yield from FinitePosets_n(n)
n += 1

Finite = LazyImport('sage.categories.finite_posets', 'FinitePosets')
Expand Down
3 changes: 1 addition & 2 deletions src/sage/coding/guruswami_sudan/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def _flatten_once(lstlst):
[1, 2, 3, 4, 5, 6]
"""
for lst in lstlst:
for e in lst:
yield e
yield from lst

#*************************************************************
# Linear algebraic Interpolation algorithm, helper functions
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/abstract_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,7 @@ def paths_at_depth(self, depth, path=[]):
yield tuple(path)
else:
for i in range(len(self)):
for p in self[i].paths_at_depth(depth - 1, path + [i]):
yield p
yield from self[i].paths_at_depth(depth - 1, path + [i])

def node_number_at_depth(self, depth):
r"""
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/alternating_sign_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,8 +1908,7 @@ def __iter__(self):
[[1, 2, 3], [2, 3], [2]],
[[1, 2, 3], [2, 3], [3]]]
"""
for z in self._iterator_rec(self.n):
yield z
yield from self._iterator_rec(self.n)


def _next_column_iterator(previous_column, height, i=None):
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/cluster_algebra_quiver/cluster_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3878,8 +3878,7 @@ def b_matrix_class_iter(self, depth=infinity, up_to_equivalence=True):
]
"""
Q = self.quiver()
for M in Q.mutation_class_iter(depth=depth, up_to_equivalence=up_to_equivalence, data_type='matrix'):
yield M
yield from Q.mutation_class_iter(depth=depth, up_to_equivalence=up_to_equivalence, data_type='matrix')

def b_matrix_class(self, depth=infinity, up_to_equivalence=True):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/colored_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ def _coerce_map_from_(self, C):
[1 if v == 0 else -1
for v in x._colors],
x._perm)
return super(SignedPermutations, self)._coerce_map_from_(C)
return super()._coerce_map_from_(C)

def long_element(self, index_set=None):
"""
Expand Down Expand Up @@ -1587,7 +1587,7 @@ def long_element(self, index_set=None):
True
"""
if index_set is not None:
return super(SignedPermutations, self).long_element()
return super().long_element()
return self.element_class(self, [-ZZ.one()] * self._n, self._P.one())

def conjugacy_class_representative(self, nu):
Expand Down
6 changes: 2 additions & 4 deletions src/sage/combinat/combinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,7 @@ def __iterator_from_list(self) -> Iterator:
sage: list(C) # indirect doctest
[1, 2, 3]
"""
for x in self.list():
yield x
yield from self.list()

def __iter__(self):
"""
Expand Down Expand Up @@ -2574,8 +2573,7 @@ def __iter__(self) -> Iterator:
raise NotImplementedError
i = 0
while True:
for c in finite(i):
yield c
yield from finite(i)
i += 1


Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/designs/design_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
'OAMainFunctions', as_='orthogonal_arrays')

lazy_import('sage.combinat.designs.gen_quadrangles_with_spread',
('generalised_quadrangle_with_spread', 'generalised_quadrangle_hermitian_with_ovoid'))
('generalised_quadrangle_with_spread', 'generalised_quadrangle_hermitian_with_ovoid'))
6 changes: 2 additions & 4 deletions src/sage/combinat/finite_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5406,8 +5406,7 @@ def _iter_transitions_all_(self):
[('1', '2'), ('2', '2')]
"""
for state in self.iter_states():
for t in state.transitions:
yield t
yield from state.transitions

def initial_states(self):
"""
Expand Down Expand Up @@ -6461,8 +6460,7 @@ def _iter_process_simple_(self, iterator):
"here." %
(len(branch.outputs),))

for o in branch.outputs[0]:
yield o
yield from branch.outputs[0]
branch.outputs[0] = []
# Reset output so that in the next round
# (of "for current in iterator") only new
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def __classcall_private__(cls, base_ring, basis_keys=None, category=None,
latex_names = tuple(latex_names)
keywords['latex_names'] = latex_names

return super(CombinatorialFreeModule, cls).__classcall__(cls,
return super().__classcall__(cls,
base_ring, basis_keys, category=category, prefix=prefix, names=names,
**keywords)

Expand Down Expand Up @@ -1674,7 +1674,7 @@ def _coerce_map_from_(self, R):
[vector_map[i](M.monomial(x[i]))
for i, M in enumerate(modules)]), codomain=self)

return super(CombinatorialFreeModule_Tensor, self)._coerce_map_from_(R)
return super()._coerce_map_from_(R)


class CartesianProductWithFlattening():
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/integer_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __classcall__(cls, row_sums, column_sums):
from sage.combinat.composition import Composition
row_sums = Composition(row_sums)
column_sums = Composition(column_sums)
return super(IntegerMatrices, cls).__classcall__(cls, row_sums, column_sums)
return super().__classcall__(cls, row_sums, column_sums)

def __init__(self, row_sums, column_sums):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/integer_vector_weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __classcall_private__(cls, n=None, weight=None):
if n is None:
return WeightedIntegerVectors_all(weight)

return super(WeightedIntegerVectors, cls).__classcall__(cls, n, weight)
return super().__classcall__(cls, n, weight)

def __init__(self, n, weight):
"""
Expand Down
6 changes: 2 additions & 4 deletions src/sage/combinat/k_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -4104,8 +4104,7 @@ def __iter__(self):
yield self([[None]*(row) for row in self._inner_shape])
else:
for unT in StrongTableaux.standard_unmarked_iterator( self.k, size, self._outer_shape, self._inner_shape ):
for T in StrongTableaux.marked_given_unmarked_and_weight_iterator( unT, self.k, self._weight ):
yield T
yield from StrongTableaux.marked_given_unmarked_and_weight_iterator( unT, self.k, self._weight )

@classmethod
def standard_unmarked_iterator( cls, k, size, outer_shape=None, inner_shape=[] ):
Expand Down Expand Up @@ -4410,8 +4409,7 @@ def standard_marked_iterator( cls, k, size, outer_shape=None, inner_shape=[] ):
[[]]
"""
for T in cls.standard_unmarked_iterator( k, size, outer_shape, inner_shape ):
for TT in cls.marked_given_unmarked_and_weight_iterator( T, k, [1]*(size) ):
yield TT
yield from cls.marked_given_unmarked_and_weight_iterator( T, k, [1]*(size) )

@classmethod
def cells_head_dictionary( cls, T ):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/lr_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __classcall_private__(cls, shape, weight):
weight = tuple(Partition(a) for a in weight)
if shape.size() != sum(a.size() for a in weight):
raise ValueError("the sizes of shapes and sequence of weights do not match")
return super(LittlewoodRichardsonTableaux, cls).__classcall__(cls, shape, weight)
return super().__classcall__(cls, shape, weight)

def __init__(self, shape, weight):
r"""
Expand All @@ -193,7 +193,7 @@ def __init__(self, shape, weight):
self._shape = shape
self._weight = weight
self._heights = [a.length() for a in self._weight]
super(LittlewoodRichardsonTableaux, self).__init__(category=FiniteEnumeratedSets())
super().__init__(category=FiniteEnumeratedSets())

def _repr_(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/plane_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ def __init__(self, n):
<class 'sage.combinat.plane_partition.PlanePartitions_n_with_category'>
sage: TestSuite(PP).run()
"""
super(PlanePartitions_n, self).__init__(category=FiniteEnumeratedSets())
super().__init__(category=FiniteEnumeratedSets())
self._n = n

def _repr_(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/recognizable_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def __init__(self, parent, mu, left, right):
sage: S.mu[0] is M0, S.mu[1] is M1, S.left is L, S.right is R
(True, True, True, True)
"""
super(RecognizableSeries, self).__init__(parent=parent)
super().__init__(parent=parent)

from copy import copy
from sage.matrix.constructor import Matrix
Expand Down Expand Up @@ -1660,7 +1660,7 @@ def __classcall__(cls, *args, **kwds):
sage: Rec1 is Rec2 is Rec3
True
"""
return super(RecognizableSeriesSpace, cls).__classcall__(
return super().__classcall__(
cls, *cls.__normalize__(*args, **kwds))

@classmethod
Expand Down Expand Up @@ -1782,7 +1782,7 @@ def __init__(self, coefficient_ring, indices, category, minimize_results):
"""
self._indices_ = indices
self._minimize_results_ = minimize_results
super(RecognizableSeriesSpace, self).__init__(
super().__init__(
category=category, base=coefficient_ring)

def __reduce__(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ def some_elements(self):
"""
return iter(element.regenerated()
for element
in super(RegularSequenceRing, self).some_elements(
in super().some_elements(
allow_degenerated_sequence=True))

def _element_constructor_(self, *args, **kwds):
Expand All @@ -1537,7 +1537,7 @@ def _element_constructor_(self, *args, **kwds):
2-regular sequence 1, 3, 6, 9, 12, 18, 18, 27, 24, 36, ...
"""
allow_degenerated_sequence = kwds.pop('allow_degenerated_sequence', False)
element = super(RegularSequenceRing, self)._element_constructor_(*args, **kwds)
element = super()._element_constructor_(*args, **kwds)
if not allow_degenerated_sequence:
element._error_if_degenerated_()
return element
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/ribbon_shaped_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class based on input.
# return RibbonShapedTableaux_shape(Partition(shape))

# Otherwise arg0 takes the place of the category in pickling
return super(RibbonShapedTableaux, cls).__classcall__(cls, **kwds)
return super().__classcall__(cls, **kwds)

def __init__(self, category=None):
"""
Expand Down Expand Up @@ -262,7 +262,7 @@ class based on input.
return StandardRibbonShapedTableaux_shape(Partition(shape))

# Otherwise arg0 takes the place of the category in pickling
return super(StandardRibbonShapedTableaux, cls).__classcall__(cls, **kwds)
return super().__classcall__(cls, **kwds)

def __init__(self, category=None):
"""
Expand Down
12 changes: 5 additions & 7 deletions src/sage/combinat/rigged_configurations/kleber_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def __classcall_private__(cls, cartan_type, B, classical=None):
classical = cartan_type.classical()
else:
classical = CartanType(classical)
return super(KleberTree, cls).__classcall__(cls, cartan_type, B, classical)
return super().__classcall__(cls, cartan_type, B, classical)

def __init__(self, cartan_type, B, classical_ct):
r"""
Expand Down Expand Up @@ -811,8 +811,7 @@ def _children_iter(self, node):
# tradeoff occurs between the methods. However, this may grow as
# the _children_iter_vector is further optimized.
if node != self.root and prod(val+1 for val in node.up_root.coefficients()) < 1000:
for x in self._children_iter_vector(node):
yield x
yield from self._children_iter_vector(node)
return

n = self._classical_ct.rank()
Expand Down Expand Up @@ -985,8 +984,7 @@ def _depth_first_iter(self, cur):
yield cur

for child in cur.children:
for x in self._depth_first_iter(child):
yield x
yield from self._depth_first_iter(child)

__iter__ = breadth_first_iter

Expand Down Expand Up @@ -1160,7 +1158,7 @@ def __classcall_private__(cls, cartan_type, B):
return KleberTreeTypeA2Even(cartan_type, B)
if cartan_type.classical().is_simply_laced():
raise ValueError("use KleberTree for simply-laced types")
return super(VirtualKleberTree, cls).__classcall__(cls, cartan_type, B)
return super().__classcall__(cls, cartan_type, B)

def __init__(self, cartan_type, B):
"""
Expand Down Expand Up @@ -1354,7 +1352,7 @@ def __classcall_private__(cls, cartan_type, B):
cartan_type = CartanType(cartan_type)
# Standardize B input into a tuple of tuples
B = tuple(map(tuple, B))
return super(KleberTreeTypeA2Even, cls).__classcall__(cls, cartan_type, B)
return super().__classcall__(cls, cartan_type, B)

def __init__(self, cartan_type, B):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/rigged_configurations/kr_tableaux.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def tensor(self, *crystals, **options):
elif isinstance(B, KirillovReshetikhinTableaux):
dims.append([B._r, B._s])
return TensorProductOfKirillovReshetikhinTableaux(ct, dims)
return super(KirillovReshetikhinTableaux, self).tensor(*crystals, **options)
return super().tensor(*crystals, **options)

@lazy_attribute
def _tableau_height(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/rigged_configurations/rc_crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __classcall_private__(cls, cartan_type, wt=None, WLR=None):
if isinstance(cartan_type, CartanTypeFolded):
return CrystalOfNonSimplyLacedRC(cartan_type, wt, WLR)

return super(CrystalOfRiggedConfigurations, cls).__classcall__(cls, wt, WLR=WLR)
return super().__classcall__(cls, wt, WLR=WLR)

def __init__(self, wt, WLR):
r"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/rigged_configurations/rc_infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __classcall_private__(cls, cartan_type):
return InfinityCrystalOfNonSimplyLacedRC(cartan_type)

cartan_type = CartanType(cartan_type)
return super(InfinityCrystalOfRiggedConfigurations, cls).__classcall__(cls, cartan_type)
return super().__classcall__(cls, cartan_type)

def __init__(self, cartan_type):
r"""
Expand Down Expand Up @@ -241,7 +241,7 @@ def _coerce_map_from_(self, P):
and self.cartan_type().is_simply_laced()):
from sage.combinat.rigged_configurations.bij_infinity import FromTableauIsomorphism
return FromTableauIsomorphism(Hom(P, self))
return super(InfinityCrystalOfRiggedConfigurations, self)._coerce_map_from_(P)
return super()._coerce_map_from_(P)

def _calc_vacancy_number(self, partitions, a, i, **options):
r"""
Expand Down Expand Up @@ -358,7 +358,7 @@ def _coerce_map_from_(self, P):
if isinstance(P, InfinityCrystalOfTableaux):
from sage.combinat.rigged_configurations.bij_infinity import FromTableauIsomorphism
return FromTableauIsomorphism(Hom(P, self))
return super(InfinityCrystalOfNonSimplyLacedRC, self)._coerce_map_from_(P)
return super()._coerce_map_from_(P)

def _calc_vacancy_number(self, partitions, a, i):
r"""
Expand Down
Loading

0 comments on commit 8c50663

Please sign in to comment.