Skip to content

use ruff to auto-simplify SIM110 #40258

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

Merged
merged 5 commits into from
Jul 6, 2025
Merged
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
5 changes: 1 addition & 4 deletions src/sage/categories/regular_crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,7 @@ def dual_equivalence_graph(self, X=None, index_set=None, directed=True):
index_set = self.index_set()

def wt_zero(x):
for i in index_set:
if x.epsilon(i) != x.phi(i):
return False
return True
return all(x.epsilon(i) == x.phi(i) for i in index_set)

if X is None:
X = [x for x in self if wt_zero(x)]
Expand Down
12 changes: 5 additions & 7 deletions src/sage/coding/linear_code_no_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def __hash__(self):
G = self.generator_matrix()
return hash((Str, G)) ^ hash(Str) ^ hash(G)

def is_subcode(self, other):
def is_subcode(self, other) -> bool:
"""
Return ``True`` if ``self`` is a subcode of ``other``.

Expand Down Expand Up @@ -880,7 +880,7 @@ def is_subcode(self, other):
G = self.generator_matrix()
return all(r in other for r in G.rows())

def is_permutation_automorphism(self, g):
def is_permutation_automorphism(self, g) -> bool:
r"""
Return `1` if `g` is an element of `S_n` (`n` = length of ``self``) and
if `g` is an automorphism of ``self``.
Expand All @@ -907,11 +907,9 @@ def is_permutation_automorphism(self, g):
basis = self.generator_matrix().rows()
H = self.parity_check_matrix()
V = H.column_space()
HGm = H*g.matrix()
for c in basis:
if HGm*c != V(0):
return False
return True
HGm = H * g.matrix()
V0 = V.zero()
return all(HGm * c == V0 for c in basis)

def permuted_code(self, p):
r"""
Expand Down
10 changes: 3 additions & 7 deletions src/sage/combinat/bijectionist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2762,13 +2762,9 @@
coeff * values[index_block_value_dict[index]]
for index, coeff in f.dict().items())

for lhs, rhs in constraint.equations():
if evaluate(lhs - rhs):
return False
for lhs, rhs in constraint.inequalities():
if evaluate(lhs - rhs) > 0:
return False
return True
if any(evaluate(lhs - rhs) for lhs, rhs in constraint.equations()):
return False
return all(evaluate(lhs - rhs) <= 0 for lhs, rhs in constraint.inequalities())

def add_alpha_beta_constraints(self):
r"""
Expand Down Expand Up @@ -3135,7 +3131,7 @@
sage: bij = Bijectionist(sum(As, []), sum(Bs, []))
sage: bij.set_statistics((lambda x: x[0], lambda x: x[0]))
sage: bij.set_intertwining_relations((2, c1, c1), (1, c2, c2))
sage: l = list(bij.solutions_iterator()); len(l) # long time -- (2.7 seconds with SCIP on AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx)

Check warning on line 3134 in src/sage/combinat/bijectionist.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Warning: slow doctest:

slow doctest:

Check warning on line 3134 in src/sage/combinat/bijectionist.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[a-f]*)

Warning: slow doctest:

slow doctest:
64

A brute force check would be difficult::
Expand Down Expand Up @@ -3163,7 +3159,7 @@
sage: A = sum(As, [])
sage: respects_c1 = lambda s: all(c1(a1, a2) not in A or s[c1(a1, a2)] == c1(s[a1], s[a2]) for a1 in A for a2 in A)
sage: respects_c2 = lambda s: all(c2(a1) not in A or s[c2(a1)] == c2(s[a1]) for a1 in A)
sage: l2 = [s for s in it if respects_c1(s) and respects_c2(s)] # long time -- (17 seconds on AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx)

Check warning on line 3162 in src/sage/combinat/bijectionist.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[a-f]*)

Warning: slow doctest:

slow doctest:
sage: sorted(l1, key=lambda s: tuple(s.items())) == l2 # long time
True

Expand Down
5 changes: 1 addition & 4 deletions src/sage/combinat/designs/covering_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ def is_covering(self):
for z in Skt:
y = (a[x] for x in z)
tset[tuple(y)] = True
for i in Svt:
if not tset[tuple(i)]: # uncovered
return False
return True # everything was covered
return all(tset[tuple(i)] for i in Svt) # everything was covered

def v(self):
"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/combinat/designs/difference_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -2029,10 +2029,7 @@ def is_fixed_relative_difference_set(R, q):
sage: is_fixed_relative_difference_set(s2, len(s2)) # needs sage.libs.pari sage.modules
False
"""
for el in R:
if q * el not in R:
return False
return True
return all(q * el in R for el in R)


def skew_supplementary_difference_set_over_polynomial_ring(n, existence=False, check=True):
Expand Down
12 changes: 4 additions & 8 deletions src/sage/combinat/ncsym/ncsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,8 @@ def _m_to_p_on_basis(self, A):
def lt(s, t):
if s == t:
return False
for p in s:
if len([z for z in t if z.intersection(p)]) != 1:
return False
return True
return all(len([1 for z in t if z.intersection(p)]) == 1
for p in s)

p = self.realization_of().p()
P = Poset((A.coarsenings(), lt))
Expand Down Expand Up @@ -1733,10 +1731,8 @@ def _x_to_p_on_basis(self, A):
def lt(s, t):
if s == t:
return False
for p in s:
if len([z for z in t if z.intersection(p)]) != 1:
return False
return True
return all(len([1 for z in t if z.intersection(p)]) == 1
for p in s)

p = self.realization_of().p()
P_refine = Poset((A.refinements(), lt))
Expand Down
20 changes: 5 additions & 15 deletions src/sage/combinat/partition_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _repr_(self):
s = self.k + 1
return "Set partitions of {1, ..., %s, -1, ..., -%s} with %s and -%s in the same block" % (s, s, s, s)

def __contains__(self, x):
def __contains__(self, x) -> bool:
"""
TESTS::

Expand All @@ -207,11 +207,8 @@ def __contains__(self, x):
if x not in SetPartitionsAk_k(self.k + 1):
return False

for part in x:
if self.k + 1 in part and -self.k - 1 not in part:
return False

return True
return all(self.k + 1 not in part or -self.k - 1 in part
for part in x)

def __iter__(self):
"""
Expand Down Expand Up @@ -668,11 +665,7 @@ def __contains__(self, x):
if not SetPartitionsAk_k.__contains__(self, x):
return False

for part in x:
if len(part) != 2:
return False

return True
return all(len(part) == 2 for part in x)

def cardinality(self):
r"""
Expand Down Expand Up @@ -764,10 +757,7 @@ def __contains__(self, x):
"""
if not SetPartitionsAkhalf_k.__contains__(self, x):
return False
for part in x:
if len(part) != 2:
return False
return True
return all(len(part) == 2 for part in x)

def cardinality(self):
"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8057,10 +8057,7 @@ def is_rank_symmetric(self) -> bool:
raise ValueError("the poset is not graded")
levels = self._hasse_diagram.level_sets()
h = len(levels)
for i in range(h // 2):
if len(levels[i]) != len(levels[h - 1 - i]):
return False
return True
return all(len(levels[i]) == len(levels[h - 1 - i]) for i in range(h // 2))

def is_slender(self, certificate=False) -> bool | tuple:
r"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/combinat/root_system/root_lattice_realizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4435,10 +4435,7 @@ def is_parabolic_root(self, index_set):
sage: alpha.is_parabolic_root([2])
False
"""
for i in self.support():
if i not in index_set:
return False
return True
return all(i in index_set for i in self.support())

def is_short_root(self):
r"""
Expand Down
6 changes: 1 addition & 5 deletions src/sage/combinat/set_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2099,11 +2099,7 @@ def __contains__(self, x):
return False

# Check to make sure each element of x is a set
for s in x:
if not isinstance(s, (set, frozenset, Set_generic)):
return False

return True
return all(isinstance(s, (set, frozenset, Set_generic)) for s in x)

def _element_constructor_(self, s, check=True):
"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/combinat/sf/ns_macdonald.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,7 @@ def is_non_attacking(self):
sage: a.is_non_attacking()
True
"""
for a, b in self.attacking_boxes():
if self[a] == self[b]:
return False
return True
return all(self[a] != self[b] for a, b in self.attacking_boxes())

def weight(self):
"""
Expand Down
6 changes: 1 addition & 5 deletions src/sage/combinat/skew_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,11 +1811,7 @@ def is_ribbon(self) -> bool:
v += 1

# Check if lam[i]==mu[i] for all i >= v
for i in range(v, l_out):
if lam[i] != mu[i]:
return False

return True
return all(lam[i] == mu[i] for i in range(v, l_out))

def to_ribbon(self, check_input=True):
"""
Expand Down
8 changes: 2 additions & 6 deletions src/sage/combinat/words/finite_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -3581,13 +3581,9 @@ def has_period(self, p) -> bool:
"""
if p < 0:
return False
elif p >= len(self):
return True
else:
for i in range(len(self) - p):
if self[i] != self[i + p]:
return False
if p >= len(self):
return True
return all(self[i] == self[i + p] for i in range(len(self) - p))

def periods(self, divide_length=False):
r"""
Expand Down
15 changes: 3 additions & 12 deletions src/sage/combinat/words/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,10 +1324,7 @@ def is_erasing(self):
sage: WordMorphism('').is_erasing()
False
"""
for image in self.images():
if image.is_empty():
return True
return False
return any(image.is_empty() for image in self.images())

def is_identity(self):
r"""
Expand Down Expand Up @@ -1547,10 +1544,7 @@ def _check_primitive(self):
"""
dom_alphabet = set(self.domain().alphabet())

for image in self.images():
if not dom_alphabet <= set(image):
return False
return True
return all(dom_alphabet <= set(image) for image in self.images())

def is_primitive(self):
r"""
Expand Down Expand Up @@ -2422,10 +2416,7 @@ def has_conjugate_in_classP(self, f=None) -> bool:
sage: (fibo^2).has_conjugate_in_classP()
True
"""
for k in self.list_of_conjugates():
if k.is_in_classP(f=f):
return True
return False
return any(k.is_in_classP(f=f) for k in self.list_of_conjugates())

def dual_map(self, k=1):
r"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/crypto/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ def has_blum_prime(lbound, ubound) -> bool:
if lbound > ubound:
raise ValueError("The lower bound must be less than the upper bound.")
# now test for presence of a Blum prime
for p in primes(lbound, ubound + 1):
if mod(p, 4).lift() == 3:
return True
return False
return any(mod(p, 4).lift() == 3 for p in primes(lbound, ubound + 1))


def is_blum_prime(n):
Expand Down
5 changes: 1 addition & 4 deletions src/sage/doctest/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,7 @@
sage: available_software.issuperset(set(['internet','latex','magma'])) # random, optional - internet latex magma
True
"""
for item in other:
if item not in self:
return False
return True
return all(item in self for item in other)

Check warning on line 510 in src/sage/doctest/external.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/external.py#L510

Added line #L510 was not covered by tests

def detectable(self):
"""
Expand Down
5 changes: 1 addition & 4 deletions src/sage/functions/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ def in_operands(ex):
def is_piecewise(ex):
if ex.operator() is piecewise:
return True
for op in ex.operands():
if is_piecewise(op):
return True
return False
return any(is_piecewise(op) for op in ex.operands())
return is_piecewise(ex)

@staticmethod
Expand Down
16 changes: 3 additions & 13 deletions src/sage/geometry/polyhedron/base1.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,7 @@ def contains(self, point):
if len(p) != self.ambient_dim():
return False

for H in self.Hrep_generator():
if not H.contains(p):
return False
return True
return all(H.contains(p) for H in self.Hrep_generator())

__contains__ = contains

Expand Down Expand Up @@ -758,10 +755,7 @@ def interior_contains(self, point):
if len(p) != self.ambient_dim():
return False

for H in self.Hrep_generator():
if not H.interior_contains(p):
return False
return True
return all(H.interior_contains(p) for H in self.Hrep_generator())

def is_relatively_open(self):
r"""
Expand Down Expand Up @@ -878,8 +872,4 @@ def relative_interior_contains(self, point):
if not eq.contains(p):
return False

for ine in self.inequality_generator():
if not ine.interior_contains(p):
return False

return True
return all(ine.interior_contains(p) for ine in self.inequality_generator())
5 changes: 1 addition & 4 deletions src/sage/geometry/polyhedron/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,7 @@ def contains(self, point):
if not self.polyhedron().contains(p):
return False

for H in self.ambient_Hrepresentation():
if H.eval(p) != 0:
return False
return True
return all(H.eval(p) == 0 for H in self.ambient_Hrepresentation())

__contains__ = contains

Expand Down
5 changes: 1 addition & 4 deletions src/sage/geometry/polyhedron/ppl_lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,7 @@ def contains(self, point_coordinates):
"""
p = C_Polyhedron(point(Linear_Expression(list(point_coordinates), 1)))
is_included = Poly_Con_Relation.is_included()
for c in self.constraints():
if not p.relation_with(c).implies(is_included):
return False
return True
return all(p.relation_with(c).implies(is_included) for c in self.constraints())

@cached_method
def contains_origin(self):
Expand Down
6 changes: 1 addition & 5 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14206,11 +14206,7 @@ def is_regular(self, k=None):
if k is None:
k = next(deg_it)

for d in deg_it:
if d != k:
return False

return True
return all(d == k for d in deg_it)

# Substructures

Expand Down
Loading
Loading