Skip to content

Commit ef4cce4

Browse files
author
Release Manager
committed
gh-40313: code simplification about return True then False (ruff SIM 103) simpler code in various files, all about how to return boolean in a better way ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #40313 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Martin Rubey
2 parents 63b91cd + 538e253 commit ef4cce4

File tree

65 files changed

+110
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+110
-299
lines changed

src/sage/algebras/free_zinbiel_algebra.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ def __init__(self, variables, side):
671671
Functor.__init__(self, Rings(), Magmas())
672672
self.vars = variables
673673
self._side = side
674-
self._finite_vars = bool(isinstance(variables, (list, tuple)) or variables in Sets().Finite())
674+
self._finite_vars = (isinstance(variables, (list, tuple))
675+
or variables in Sets().Finite())
675676

676677
def _apply_functor(self, R):
677678
"""

src/sage/algebras/fusion_rings/f_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ def _get_component_variety(self, var, eqns):
18171817
# TODO: this can probably be improved by constructing a set of defining polynomials
18181818
# and checking, one by one, if it's irreducible over the current field.
18191819
# If it is, we construct an extension. Perhaps it's best to go one by one here...
1820-
def attempt_number_field_computation(self):
1820+
def attempt_number_field_computation(self) -> bool:
18211821
r"""
18221822
Based on the ``CartanType`` of ``self`` and data
18231823
known on March 17, 2021, determine whether to attempt

src/sage/algebras/shuffle_algebra.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,7 @@ def _coerce_map_from_(self, R):
539539
# shuffle algebras in the same variable over any base that coerces in:
540540
if isinstance(R, ShuffleAlgebra):
541541
if R.variable_names() == self.variable_names():
542-
if self.base_ring().has_coerce_map_from(R.base_ring()):
543-
return True
544-
else:
545-
return False
542+
return self.base_ring().has_coerce_map_from(R.base_ring())
546543

547544
if isinstance(R, DualPBWBasis):
548545
return self.has_coerce_map_from(R._alg)

src/sage/combinat/cartesian_product.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ def is_finite(self):
292292
if all(f is True for f in finites):
293293
return True
294294
lens = [_len(L) for L in self.iters]
295-
if any(l == 0 for l in lens):
296-
return True
297-
return False
295+
return any(l == 0 for l in lens)
298296

299297
def unrank(self, x):
300298
"""

src/sage/combinat/designs/difference_family.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,9 +1307,7 @@ def _is_periodic_sequence(seq, period):
13071307
break
13081308
if periodic:
13091309
return False
1310-
if seq[:period] != seq[period : 2*period]:
1311-
return False
1312-
return True
1310+
return seq[:period] == seq[period:2 * period]
13131311

13141312

13151313
def _create_m_sequence(q, n, check=True):

src/sage/combinat/gelfand_tsetlin_patterns.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,9 @@ def __contains__(self, gt):
704704
for i in range(1, len(gt)) for j in range(len(gt[i]))):
705705
return False
706706
# Check if it is strict if applicable
707-
if self._strict and any(gt[i][j] == gt[i][j-1] for i in range(len(gt))
708-
for j in range(1, len(gt[i]))):
709-
return False
710-
return True
707+
return not (self._strict and any(gt[i][j] == gt[i][j - 1]
708+
for i in range(len(gt))
709+
for j in range(1, len(gt[i]))))
711710

712711
def _repr_(self):
713712
"""

src/sage/combinat/integer_matrices.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ def __contains__(self, x):
178178
col_sums[j] += x_ij
179179
if row_sums[i] != self._row_sums[i]:
180180
return False
181-
if col_sums != self._col_sums:
182-
return False
183-
return True
181+
return col_sums == self._col_sums
184182

185183
def cardinality(self):
186184
r"""

src/sage/combinat/integer_vector.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,10 +1310,7 @@ def __contains__(self, x):
13101310
if sum(x) != self.n:
13111311
return False
13121312

1313-
if len(x) > 0 and min(x) < 0:
1314-
return False
1315-
1316-
return True
1313+
return not x or min(x) >= 0
13171314

13181315
def rank(self, x):
13191316
"""

src/sage/combinat/matrices/latin.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,7 @@ def is_latin_square(self):
728728
return False
729729

730730
# By necessity self must be a partial latin square:
731-
if not self.is_partial_latin_square():
732-
return False
733-
734-
return True
731+
return self.is_partial_latin_square()
735732

736733
def permissable_values(self, r, c):
737734
"""

src/sage/combinat/parallelogram_polyomino.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,9 +3143,7 @@ def box_is_node(self, pos) -> bool:
31433143
return False
31443144
if self[pos[0] - 1][pos[1]] == 0:
31453145
return True
3146-
if self[pos[0]][pos[1] - 1] == 0:
3147-
return True
3148-
return False
3146+
return self[pos[0]][pos[1] - 1] == 0
31493147

31503148
def box_is_root(self, box) -> bool:
31513149
r"""

0 commit comments

Comments
 (0)