Skip to content

some care for ruff RET in algebras/ #40255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/sage/algebras/cluster_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,8 +1988,7 @@ def F_polynomial(self, g_vector):
msg += "you can compute it by mutating from the initial seed along the sequence "
msg += str(self._path_dict[g_vector])
raise KeyError(msg)
else:
raise KeyError("the g-vector %s has not been found yet" % str(g_vector))
raise KeyError("the g-vector {} has not been found yet".format(g_vector))

def find_g_vector(self, g_vector, depth=infinity):
r"""
Expand Down
3 changes: 1 addition & 2 deletions src/sage/algebras/commutative_dga.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,7 @@

if isinstance(x, sage.interfaces.abc.SingularElement):
# self._singular_().set_ring()
x = self.element_class(self, x.sage_poly(self.cover_ring()))
return x
return self.element_class(self, x.sage_poly(self.cover_ring()))

Check warning on line 1289 in src/sage/algebras/commutative_dga.py

View check run for this annotation

Codecov / codecov/patch

src/sage/algebras/commutative_dga.py#L1289

Added line #L1289 was not covered by tests

return self.element_class(self, x)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ def one(self):
"""
if not self.is_unitary():
raise TypeError("algebra is not unitary")
else:
return self(self._one)
return self(self._one)

def random_element(self, *args, **kwargs):
"""
Expand Down
19 changes: 9 additions & 10 deletions src/sage/algebras/finite_gca.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@
if names is None:
if degrees is None:
raise ValueError("you must specify names or degrees")
else:
n = len(degrees)
n = len(degrees)

Check warning on line 163 in src/sage/algebras/finite_gca.py

View check run for this annotation

Codecov / codecov/patch

src/sage/algebras/finite_gca.py#L163

Added line #L163 was not covered by tests
names = tuple(f'x{i}' for i in range(n))
elif isinstance(names, str):
names = tuple(names.split(','))
Expand Down Expand Up @@ -397,13 +396,13 @@
return '1'
# Non-trivial case:
terms = []
for i in range(len(w)):
if w[i] == 0:
for i, wi in enumerate(w):
if wi == 0:
continue
elif w[i] == 1:
if wi == 1:
terms.append(self._names[i])
else:
terms.append(self._names[i] + f'^{w[i]}')
terms.append(self._names[i] + f'^{wi}')
return self._mul_symbol.join(terms)

def _latex_term(self, w) -> str:
Expand Down Expand Up @@ -432,13 +431,13 @@
return '1'
# Non-trivial case:
terms = []
for i in range(len(w)):
if w[i] == 0:
for i, wi in enumerate(w):
if wi == 0:
continue
elif w[i] == 1:
if wi == 1:
terms.append(self._names[i])
else:
terms.append(self._names[i] + '^{' + str(w[i]) + '}')
terms.append(self._names[i] + '^{' + str(wi) + '}')
latex_mul = self._mul_latex_symbol + ' ' # add whitespace
return latex_mul.join(terms)

Expand Down
7 changes: 3 additions & 4 deletions src/sage/algebras/free_algebra_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, A, x):

IndexedFreeModuleElement.__init__(self, A, x)

def _repr_(self):
def _repr_(self) -> str:
"""
Return string representation of ``self``.

Expand All @@ -104,10 +104,9 @@ def _repr_(self):
M = P.monoid()
from sage.structure.parent_gens import localvars
with localvars(M, P.variable_names(), normalize=False):
x = repr_lincomb(v, strip_one=True)
return x
return repr_lincomb(v, strip_one=True)

def _latex_(self):
def _latex_(self) -> str:
r"""
Return latex representation of ``self``.

Expand Down
14 changes: 5 additions & 9 deletions src/sage/algebras/fusion_rings/f_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,12 +1379,9 @@
else:
mapped = worker_pool.imap_unordered(executor, input_iter, chunksize=chunksize)
# Reduce phase
results = set()
for child_eqns in mapped:
if child_eqns is not None:
results.update(child_eqns)
results = list(results)
return results
results = {eqn for child_eqns in mapped for eqn in child_eqns
if child_eqns is not None}
return list(results)

########################
# Equations set up #
Expand Down Expand Up @@ -1770,8 +1767,7 @@
small_comps.append(comp_eqns)
input_iter = zip_longest(small_comps, [], fillvalue=term_order)
small_comp_gb = self._map_triv_reduce('compute_gb', input_iter, worker_pool=self.pool, chunksize=1, mp_thresh=50)
ret = small_comp_gb + temp_eqns
return ret
return small_comp_gb + temp_eqns

def _get_component_variety(self, var, eqns):
r"""
Expand Down Expand Up @@ -2324,7 +2320,7 @@
[]
"""
if self._poly_ring.ngens() == 0:
return
return None

Check warning on line 2323 in src/sage/algebras/fusion_rings/f_matrix.py

View check run for this annotation

Codecov / codecov/patch

src/sage/algebras/fusion_rings/f_matrix.py#L2323

Added line #L2323 was not covered by tests
self._reset_solver_state()
self._var_to_sextuple = {self._poly_ring.gen(i): s for i, s in self._idx_to_sextuple.items()}

Expand Down
6 changes: 3 additions & 3 deletions src/sage/algebras/fusion_rings/fusion_double.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ def s_matrix(self, unitary=False, base_coercion=True):
[ 1/3 1/3 -1/3 0 0 -1/3 2/3 -1/3]
"""
b = self.basis()
S = matrix([[self.s_ij(b[x], b[y], unitary=unitary, base_coercion=base_coercion)
for x in self.get_order()] for y in self.get_order()])
return S
return matrix([[self.s_ij(b[x], b[y], unitary=unitary,
base_coercion=base_coercion)
for x in self.get_order()] for y in self.get_order()])

@cached_method
def N_ijk(self, i, j, k):
Expand Down
14 changes: 4 additions & 10 deletions src/sage/algebras/hecke_algebras/cubic_hecke_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,6 @@ def product_on_basis(self, g1, g2):
g1 = self.monomial(g1)
g2 = self.monomial(g2)

result = None

g1_Tietze = g1.Tietze()
g2_Tietze = g2.Tietze()

Expand All @@ -1563,9 +1561,8 @@ def product_on_basis(self, g1, g2):
# The product is calculated from the corresponding product of the braids
# ----------------------------------------------------------------------
braid_group = self.braid_group()
braid_product = braid_group(g1_Tietze+g2_Tietze)
result = self._braid_image(braid_product)
return result
braid_product = braid_group(g1_Tietze + g2_Tietze)
return self._braid_image(braid_product)

############################################################################
# --------------------------------------------------------------------------
Expand Down Expand Up @@ -2043,8 +2040,7 @@ def _braid_image_from_reduced_powers(self, braid_tietze):
return self.one()
k = braid_tietze[0]*len_braid
result_vect = self._reduce_gen_power(k)
result = self.from_vector(result_vect)
return result
return self.from_vector(result_vect)

# ----------------------------------------------------------------------
# Try to use former calculations (from dynamic library) to obtain the
Expand Down Expand Up @@ -2094,8 +2090,7 @@ def _braid_image_from_reduced_powers(self, braid_tietze):
braid_preimage = tuple(word_result)
result_vect = self._mult_by_regular_rep(vect, tuple(word_right), RepresentationType.RegularRight, braid_preimage)

result = self.from_vector(result_vect)
return result
return self.from_vector(result_vect)

# --------------------------------------------------------------------------
# _braid_image_from_former_calculations
Expand Down Expand Up @@ -2649,7 +2644,6 @@ def _extend_braid_automorphism(self, element, braid_automorphism):
sage: CHA2.mirror_isomorphism(br) # indirect doctest
c^-1
"""

result = self.zero()
for braid in element.support():
autom_braid = braid_automorphism(braid)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/hecke_algebras/cubic_hecke_base_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def construction(self):
sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')
sage: ER._test_category() # indirect doctest
"""
return None
return

def __reduce__(self):
r"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/algebras/hecke_algebras/cubic_hecke_matrix_rep.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def construction(self):
sage: MS = c1.matrix().parent()
sage: MS._test_category() # indirect doctest
"""
return None
return

def __reduce__(self):
r"""
Expand Down Expand Up @@ -894,8 +894,8 @@ def invert_gen(matr):
matri += cf2 * matr
matri += cf3 * matr**2
d1, d2 = matr.dimensions()
matrI = matrix(original_base_ring, d1, d2, lambda i, j: original_base_ring(matri[i, j]))
return matrI
return matrix(original_base_ring, d1, d2,
lambda i, j: original_base_ring(matri[i, j]))

if n == 2:
if representation_type.is_split():
Expand Down
3 changes: 1 addition & 2 deletions src/sage/algebras/lie_algebras/center_uea.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ def some_elements(self):
ret = set(gens)
ret.update([self.prod(gens), gens[1] * gens[3]**4, gens[1]**4 * gens[2]**3])
# Sort the output for uniqueness
ret = sorted(ret, key=lambda m: (self.degree(m), m.to_word_list()))
return ret
return sorted(ret, key=lambda m: (self.degree(m), m.to_word_list()))

def degree(self, m):
r"""
Expand Down
16 changes: 8 additions & 8 deletions src/sage/algebras/lie_algebras/free_lie_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ def _rewrite_bracket(self, l, r):
for m, inner_coeff in self._rewrite_bracket(l, r._right).items():
if r._left == m:
continue
elif r._left < m:
if r._left < m:
x, y = r._left, m
else: # r._left > m
else: # r._left > m
x, y = m, r._left
inner_coeff = -inner_coeff
for b_elt, coeff in self._rewrite_bracket(x, y).items():
Expand All @@ -644,9 +644,9 @@ def _rewrite_bracket(self, l, r):
for m, inner_coeff in self._rewrite_bracket(l, r._left).items():
if m == r._right:
continue
elif m < r._right:
if m < r._right:
x, y = m, r._right
else: # m > r._right
else: # m > r._right
x, y = r._right, m
inner_coeff = -inner_coeff
for b_elt, coeff in self._rewrite_bracket(x, y).items():
Expand Down Expand Up @@ -739,9 +739,9 @@ def _rewrite_bracket(self, l, r):
for m, inner_coeff in self._rewrite_bracket(l._right, r).items():
if l._left == m:
continue
elif l._left < m:
if l._left < m:
x, y = l._left, m
else: # l._left > m
else: # l._left > m
x, y = m, l._left
inner_coeff = -inner_coeff
for b_elt, coeff in self._rewrite_bracket(x, y).items():
Expand All @@ -751,9 +751,9 @@ def _rewrite_bracket(self, l, r):
for m, inner_coeff in self._rewrite_bracket(l._left, r).items():
if m == l._right:
continue
elif m < l._right:
if m < l._right:
x, y = m, l._right
else: # m > l._right
else: # m > l._right
x, y = l._right, m
inner_coeff = -inner_coeff
for b_elt, coeff in self._rewrite_bracket(x, y).items():
Expand Down
4 changes: 2 additions & 2 deletions src/sage/algebras/lie_algebras/verma_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ def _acted_upon_(self, scalar, self_on_left=False):
for m in ret._monomial_coefficients:
c = ret._monomial_coefficients[m]
mp = {}
for k,e in reversed(m._sorted_items()):
for k, e in reversed(m._sorted_items()):
part = P._g._part_on_basis(k)
if part > 0:
mp = None
break
elif part == 0:
if part == 0:
c *= P._g._weight_action(k, P._weight)**e
else:
mp[k] = e
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/orlik_solomon.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def construction(self):
sage: OS1.construction() is None
True
"""
return None
return

def _basis_action(self, g, f):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/orlik_terao.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def construction(self):
sage: OTG.construction() is None
True
"""
return None
return

def _basis_action(self, g, f):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/quantum_matrix_coordinate_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def product_on_basis(self, a, b):
if ax[0] < bx[0]:
# In order, so nothing more to do
break
elif ax[0] == bx[0]:
if ax[0] == bx[0]:
if ax[1] > bx[1]:
# x_{it} x_{ij} = q^{-1} x_{ij} x_{it} if t < j
coeff *= qi ** (ae * be)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/schur_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def construction(self):
sage: T = SchurTensorModule(QQ, 2, 3)
sage: T.construction()
"""
return None
return

def _monomial_product(self, xi, v):
"""
Expand Down
Loading
Loading