Skip to content
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

fix ruff PLR1730 checks #38540

Open
wants to merge 8 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
12 changes: 4 additions & 8 deletions src/sage/calculus/desolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,14 +1357,10 @@ def desolve_rk4_inner(de, dvar):
XMAX = XMIN
YMAX = YMIN
for s, t in sol:
if s > XMAX:
XMAX = s
if s < XMIN:
XMIN = s
if t > YMAX:
YMAX = t
if t < YMIN:
YMIN = t
XMAX = max(s, XMAX)
XMIN = min(s, XMIN)
YMAX = max(t, YMAX)
YMIN = min(t, YMIN)
return plot_slope_field(de, (ivar, XMIN, XMAX), (dvar, YMIN, YMAX)) + R

if not (isinstance(dvar, Expression) and dvar.is_symbol()):
Expand Down
6 changes: 2 additions & 4 deletions src/sage/categories/finite_posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,7 @@ def rowmotion_orbits_plots(self):
max_orbit_size = 0
for orb in self.rowmotion_orbits():
orb_plots = []
if len(orb) > max_orbit_size:
max_orbit_size = len(orb)
max_orbit_size = max(len(orb), max_orbit_size)
for oi in orb:
oiplot = self.order_ideal_plot(oi)
orb_plots.append(oiplot)
Expand Down Expand Up @@ -1565,8 +1564,7 @@ def toggling_orbits_plots(self, vs):
max_orbit_size = 0
for orb in self.toggling_orbits(vs):
orb_plots = []
if len(orb) > max_orbit_size:
max_orbit_size = len(orb)
max_orbit_size = max(len(orb), max_orbit_size)
for oi in orb:
oiplot = self.order_ideal_plot(oi)
orb_plots.append(oiplot)
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/matrices/latin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,7 @@ def disjoint_mate_dlxcpp_rows_and_map(self, allow_subtrade):

dlx_rows.append([c_OFFSET, r_OFFSET, xy_OFFSET])

if max_column_nr < max(c_OFFSET, r_OFFSET, xy_OFFSET):
max_column_nr = max(c_OFFSET, r_OFFSET, xy_OFFSET)
max_column_nr = max(max_column_nr, max(c_OFFSET, r_OFFSET, xy_OFFSET))

# We will have missed some columns. We
# have to add 'dummy' rows so that the C++ DLX solver will find
Expand Down
9 changes: 3 additions & 6 deletions src/sage/combinat/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8229,8 +8229,7 @@ def _fast_iterator(self, n, max_part):
yield []
return

if n < max_part:
max_part = n
max_part = min(n, max_part)
bdry = self._ell - 1

for i in reversed(range(1, max_part + 1)):
Expand Down Expand Up @@ -8421,8 +8420,7 @@ def _fast_iterator(self, n, max_part, depth=0):
yield [n]
return

if n < max_part:
max_part = n
max_part = min(n, max_part)
bdry = self._ell - 1

for i in reversed(range(1, max_part + 1)):
Expand Down Expand Up @@ -9066,8 +9064,7 @@ def _fast_iterator(self, n, max_part):
yield []
return

if n < max_part:
max_part = n
max_part = min(n, max_part)

for i in range(max_part, 0, -1):
for p in self._fast_iterator(n-i, i):
Expand Down
6 changes: 2 additions & 4 deletions src/sage/combinat/rigged_configurations/bij_type_D.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def next_state(self, val):
if tableau_height <= n - 2:
max_width2 = self.ret_rig_con[n - 2].insert_cell(max_width)
max_width = self.ret_rig_con[n - 1].insert_cell(max_width)
if max_width2 < max_width:
max_width = max_width2
max_width = min(max_width2, max_width)
elif pos_val <= self.cur_dims[0][0]:
# Special case when the height will become n
max_width = self.ret_rig_con[self.cur_dims[0][0] - 1].insert_cell(max_width)
Expand Down Expand Up @@ -603,8 +602,7 @@ def next_state(self, height):
temp_size = self.cur_partitions[n - 2][ell[n - 2]]
if ell[n - 1] is not None:
last_size = self.cur_partitions[n - 1][ell[n - 1]]
if temp_size > last_size:
last_size = temp_size
last_size = max(temp_size, last_size)
else:
b = n
else:
Expand Down
6 changes: 2 additions & 4 deletions src/sage/combinat/sloane_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6794,8 +6794,7 @@ def _powerful_numbers_in_range(self, n, m):
# This is naive -- too slow; too much overhead
# return [i for i in range(self._n, self._n+how_many) if self.is_powerful(i)]

if n < 4:
n = 4
n = max(n, 4)
# Use PARI directly -- much faster.
from sage.libs.pari.all import pari
L = pari('v=listcreate(); for(i=%s,%s,if(vecmin(factor(i)[,2])>1,listput(v,i))); v' % (n, m))
Expand Down Expand Up @@ -8315,8 +8314,7 @@ def _eval(self, n):
continue
# d is odd divisor
k = min(d, 2 * n // d)
if k > m:
m = k
m = max(k, m)
return ZZ(m)


Expand Down
9 changes: 3 additions & 6 deletions src/sage/combinat/words/finite_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,7 @@ def good_suffix_table(self):
res = [l - p[-1]]*(l+1)
for i in range(1, l+1):
j = l - p[i - 1]
if res[j] > (i - p[i-1]):
res[j] = i - p[i-1]
res[j] = min(res[j], i - p[i-1])
return res

@cached_method
Expand Down Expand Up @@ -3455,8 +3454,7 @@ def critical_exponent(self):
current_pos = k-j+l-1
pft[current_pos] = m
current_exp = QQ((current_pos+1, current_pos+1-m))
if current_exp > best_exp:
best_exp = current_exp
best_exp = max(current_exp, best_exp)
for ((i, j), u) in st._transition_function[v].items():
if j is None:
j = self.length()
Expand Down Expand Up @@ -6319,8 +6317,7 @@ def delta(self):
for s in self:
if s == ss:
c += 1
if c > max_c:
max_c = c
max_c = max(c, max_c)
else:
v.append(c)
ss = s
Expand Down
12 changes: 4 additions & 8 deletions src/sage/combinat/words/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,10 +1801,8 @@ def height_vector(self):
y_min = y
y_max = y
else:
if y > y_max:
y_max = y
if y < y_min:
y_min = y
y_max = max(y, y_max)
y_min = min(y, y_min)
h_vec.append(y_max - y_min)
return h_vec

Expand Down Expand Up @@ -1866,10 +1864,8 @@ def width_vector(self):
x_min = x
x_max = x
else:
if x > x_max:
x_max = x
if x < x_min:
x_min = x
x_max = max(x, x_max)
x_min = min(x, x_min)
w_vec.append(x_max - x_min)
return w_vec

Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/words/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,7 @@ def iter_morphisms(self, arg=None, codomain=None, min_length=1):
TypeError: codomain (=a) must be an instance of FiniteWords
"""
n = self.alphabet().cardinality()
if min_length < 0:
min_length = 0
min_length = max(min_length, 0)
# create an iterable of compositions (all "compositions" if arg is
# None, or [arg] otherwise)
if arg is None:
Expand Down
6 changes: 2 additions & 4 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1944,8 +1944,7 @@ def sel_exit():
# has the messages pipe open).
# Adjust deadline to read all messages:
newdeadline = now + die_timeout
if w.deadline > newdeadline:
w.deadline = newdeadline
w.deadline = min(w.deadline, newdeadline)
new_workers.append(w)
else:
# Save the result and output of the worker
Expand Down Expand Up @@ -2042,8 +2041,7 @@ def sel_exit():
# The master pselect() call
rlist = [w.rmessages for w in workers if w.rmessages is not None]
tmout = min(w.deadline for w in workers) - now
if tmout > 5: # Wait at most 5 seconds
tmout = 5
tmout = min(tmout, 5)
rlist, _, _, _ = sel.pselect(rlist, timeout=tmout)

# Read messages
Expand Down
7 changes: 2 additions & 5 deletions src/sage/dynamics/arithmetic_dynamics/endPN_minimal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,7 @@ def coshdelta(z):
red_g = f.conjugate(M*MG)
if G != pts_poly:
R2 = get_bound_dynamical(G, red_g, m=n, dynatomic=dynatomic, prec=prec, emb=emb)
if R2 < R:
# use the better bound
R = R2
R = min(R2, R)
red_g.normalize_coordinates()
if red_g.global_height(prec=prec) == 0:
return [red_g, M*MG]
Expand Down Expand Up @@ -1134,8 +1132,7 @@ def coshdelta(z):
if new_size == 1: # early exit
return [current_min[1], current_min[4]]
new_R = get_bound_dynamical(G, g, m=n, dynatomic=dynatomic, prec=prec, emb=emb)
if new_R < R:
R = new_R
R = min(new_R, R)

# add new points to check
if label != 1 and min((rep+1).norm(), (rep-1).norm()) >= 1: # don't undo S
Expand Down
6 changes: 2 additions & 4 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2120,8 +2120,7 @@ def green_function(self, P, v, **kwds):
h = max([(Res*c).local_height_arch(vindex, prec=prec) for c in poly.coefficients()])
else: #non-archimedean
h = max([c.local_height(v, prec=prec) for c in poly.coefficients()])
if h > maxh:
maxh = h
maxh = max(h, maxh)
if maxh == 0:
maxh = 1 #avoid division by 0
if isinstance(v, RingHomomorphism_im_gens): #archimedean
Expand Down Expand Up @@ -2334,8 +2333,7 @@ def canonical_height(self, P, **kwds):
if err is not None:
err = err / 2
N = ceil((R(Res).log().log() - R(d-1).log() - R(err).log())/(R(d).log()))
if N < 1:
N = 1
N = max(N, 1)
kwds.update({'error_bound': err})
kwds.update({'N': N})
for n in range(N):
Expand Down
3 changes: 1 addition & 2 deletions src/sage/geometry/polyhedral_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,8 +2074,7 @@ def add_cell(self, cell):
raise ValueError("the cell is not face-to-face with complex")
# update dim and maximal cells
d = cell.dimension()
if d > self._dim:
self._dim = d
self._dim = max(d, self._dim)
maximal_cells = poset.maximal_elements() # a list
self._maximal_cells = cells_list_to_cells_dict(maximal_cells)
# update convexity if self was known to be convex, reset otherwise.
Expand Down
6 changes: 2 additions & 4 deletions src/sage/geometry/toric_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,12 @@ def adjust_options(self):
for key in ["xmin", "ymin", "zmin"]:
if round or sd[key] is None:
sd[key] = - r
if sd[key] > - 0.5:
sd[key] = - 0.5
sd[key] = min(sd[key], - 0.5)
sd[key] = RDF(sd[key])
for key in ["xmax", "ymax", "zmax"]:
if round or sd[key] is None:
sd[key] = r
if sd[key] < 0.5:
sd[key] = 0.5
sd[key] = max(sd[key], 0.5)
sd[key] = RDF(sd[key])
if self.show_lattice is None:
self.show_lattice = (r <= 5) if d <= 2 else r <= 3
Expand Down
3 changes: 1 addition & 2 deletions src/sage/groups/additive_abelian/additive_abelian_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,7 @@ def _expand_basis_pgroup(p, alphas, vals, beta, h, rel):
q = rel[i].p_primary_part(p)
alphas[i] *= rel[i] // q
rel[i] = q
if q < min_r:
min_r = q
min_r = min(q, min_r)
if min_r == float('inf'):
raise ValueError('rel must have at least one nonzero entry')
val_rlast = rel[-1].valuation(p)
Expand Down
7 changes: 3 additions & 4 deletions src/sage/interfaces/ecm.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def interact(self):
65: 850000000,
70: 2900000000}

def _B1_table_value(self, factor_digits, min=15, max=70):
def _B1_table_value(self, factor_digits, min_val=15, max_val=70):
"""
Return key in ``_recommended_B1_list``.

Expand All @@ -290,9 +290,8 @@ def _B1_table_value(self, factor_digits, min=15, max=70):
sage: ecm._B1_table_value(33)
35
"""
if factor_digits < min:
factor_digits = min
if factor_digits > max:
factor_digits = max(factor_digits, min_val)
if factor_digits > max_val:
raise ValueError('too many digits')
step = 5
return ((factor_digits + step - 1) // step) * step
Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/magma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2906,8 +2906,7 @@ def write(self, s):
pol_curr, col_curr = map(int, match.groups())

if pol_curr != 0:
if self.max_deg < self.curr_deg:
self.max_deg = self.curr_deg
self.max_deg = max(self.max_deg, self.curr_deg)

if style == "sage" and verbosity >= 1:
print("Leading term degree: %2d. Critical pairs: %d." %
Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/singular.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,8 +2614,7 @@ def write(self, s):
if verbosity >= 1:
print("Leading term degree: %2d." % int(token))
self.curr_deg = int(token)
if self.max_deg < self.curr_deg:
self.max_deg = self.curr_deg
self.max_deg = max(self.max_deg, self.curr_deg)

elif re.match(SingularGBLogPrettyPrinter.red_para, token) and verbosity >= 3:
m, n = re.match(SingularGBLogPrettyPrinter.red_para, token).groups()
Expand Down
3 changes: 1 addition & 2 deletions src/sage/knots/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -4003,8 +4003,7 @@ def _knotinfo_matching_list(self):
# set the limits for the KnotInfoSeries
if cr > 11 and co > 1:
cr = 11
if cr > 13:
cr = 13
cr = min(cr, 13)

Hp = self.homfly_polynomial(normalization='vz')

Expand Down
13 changes: 5 additions & 8 deletions src/sage/logic/boolformula.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,12 @@ def truthtable(self, start=0, end=-1):
exponential time function requiring `O(2^n)` time, where
`n` is the number of variables in the expression.
"""
max = 2 ** len(self.__vars_order)
maximum = 2 ** len(self.__vars_order)
if end < 0:
end = max
if end > max:
end = max
if start < 0:
start = 0
if start > max:
start = max
end = maximum
end = min(end, maximum)
start = max(start, 0)
start = min(start, maximum)
keys, table = [], []
vars = {}
for var in self.__vars_order:
Expand Down
6 changes: 2 additions & 4 deletions src/sage/matrix/operation_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ def _name_maker(self, names):
width = 0
for e in self._elts:
estr = repr(e)
if len(estr) > width:
width = len(estr)
width = max(len(estr), width)
name_list.append(estr)
elif isinstance(names, list):
if len(names) != self._n:
Expand All @@ -588,8 +587,7 @@ def _name_maker(self, names):
if not isinstance(name, str):
raise ValueError(
'list of element names must only contain strings, not %s' % name)
if len(name) > width:
width = len(name)
width = max(len(name), width)
name_list.append(name)
else:
raise ValueError(
Expand Down
3 changes: 1 addition & 2 deletions src/sage/modular/modform/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,8 +1300,7 @@ def _compute_hecke_matrix_prime(self, p, prec=None):
except AttributeError:
pass
else:
if prec < cur:
prec = cur
prec = max(prec, cur)
B = self.q_expansion_basis(prec)
eps = self.character()
if eps is None:
Expand Down
3 changes: 1 addition & 2 deletions src/sage/modular/modsym/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,7 @@ def _q_expansion_basis_hecke_dual(self, prec):
prec = Integer(prec)
if prec < 1:
raise ValueError("prec (=%s) must be >= 1" % prec)
if d >= prec - 1:
d = prec - 1
d = min(prec - 1, d)
K = self.base_ring()

A = VectorSpace(K, prec - 1)
Expand Down
Loading
Loading