Skip to content

Commit 469417b

Browse files
author
Release Manager
committed
gh-41089: various small things about len about not using "if len(what):" plus a few other minor things ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #41089 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 9de3d3d + d842f51 commit 469417b

File tree

9 files changed

+24
-23
lines changed

9 files changed

+24
-23
lines changed

src/sage/calculus/calculus.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ def symbolic_expression_from_maxima_string(x, equals_sub=False, maxima=maxima):
25082508
maxima.set('_tmp_', x)
25092509

25102510
# This is inefficient since it so rarely is needed:
2511-
#r = maxima._eval_line('listofvars(_tmp_);')[1:-1]
2511+
# r = maxima._eval_line('listofvars(_tmp_);')[1:-1]
25122512

25132513
s = maxima._eval_line('_tmp_;')
25142514

@@ -2520,10 +2520,10 @@ def symbolic_expression_from_maxima_string(x, equals_sub=False, maxima=maxima):
25202520
# there is a potential very subtle bug if 'foo is in a string
25212521
# literal -- but string literals should *never* ever be part of a
25222522
# symbolic expression.
2523-
s = s.replace("'","")
2523+
s = s.replace("'", "")
25242524

25252525
delayed_functions = maxima_qp.findall(s)
2526-
if len(delayed_functions):
2526+
if delayed_functions:
25272527
for X in delayed_functions:
25282528
if X == '?%at': # we will replace Maxima's "at" with symbolic evaluation, not a SymbolicFunction
25292529
pass
@@ -2548,8 +2548,8 @@ def symbolic_expression_from_maxima_string(x, equals_sub=False, maxima=maxima):
25482548
s = s.replace("%","")
25492549

25502550
s = s.replace("#","!=") # a lot of this code should be refactored somewhere...
2551-
#we apply the square-bracket replacing patterns repeatedly
2552-
#to ensure that nested brackets get handled (from inside to out)
2551+
# we apply the square-bracket replacing patterns repeatedly
2552+
# to ensure that nested brackets get handled (from inside to out)
25532553
while True:
25542554
olds = s
25552555
s = polylog_ex.sub('polylog(\\1,', s)

src/sage/coding/codecan/codecan.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ cdef class InnerGroup:
292292
293293
d, _ = self.minimize_by_row_mult(factor * act_col)
294294
d.pop(first_nz_rep)
295-
if len(d): # there is at least one more multiplication
295+
if d: # there is at least one more multiplication
296296
group_changed[0] = True
297297
for i in range(self.rank):
298298
factor = d.get(self.get_rep(i))

src/sage/data_structures/bounded_integer_sequences.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ def _biseq_stresstest():
13881388
L[randint(0, 99)] = L[randint(0, 99)] + L[randint(0, 99)]
13891389
elif branch == 1:
13901390
x = randint(0, 99)
1391-
if len(L[x]):
1391+
if L[x]:
13921392
y = randint(0, len(L[x]) - 1)
13931393
z = randint(y, len(L[x]) - 1)
13941394
L[randint(0, 99)] = L[x][y:z]
@@ -1400,7 +1400,7 @@ def _biseq_stresstest():
14001400
t = L[randint(0, 99)].list()
14011401
elif branch == 3:
14021402
x = randint(0, 99)
1403-
if len(L[x]):
1403+
if L[x]:
14041404
y = randint(0, len(L[x])-1)
14051405
t = L[x][y]
14061406
try:

src/sage/databases/findstat.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,7 @@ def __init__(self, id, domain=None, check=True):
28022802
FindStatCombinatorialStatistic.__init__(self)
28032803
Element.__init__(self, FindStatStatistics()) # this is not completely correct, but it works
28042804

2805-
def _fetch_first_terms_raw(self):
2805+
def _fetch_first_terms_raw(self) -> list:
28062806
r"""
28072807
Return the first terms of the compound statistic, as ``(string,
28082808
value)`` pairs, fetched from FindStat.
@@ -2817,7 +2817,7 @@ def _fetch_first_terms_raw(self):
28172817
"""
28182818
fields = "Values"
28192819
url = FINDSTAT_API_STATISTICS + self.id_str() + "?fields=" + fields
2820-
if len(self._maps):
2820+
if self._maps:
28212821
values = _get_json(url)["included"]["CompoundStatistics"][self.id_str()]["Values"]
28222822
else:
28232823
values = _get_json(url)["included"]["Statistics"][self.id_str()]["Values"]
@@ -2851,7 +2851,7 @@ def __call__(self, elt):
28512851
"""
28522852
return self.statistic()(self.compound_map()(elt))
28532853

2854-
def id_str(self):
2854+
def id_str(self) -> str:
28552855
"""
28562856
Return the padded identifier of the compound statistic.
28572857
@@ -2862,7 +2862,7 @@ def id_str(self):
28622862
"""
28632863
return self._id
28642864

2865-
def _repr_(self):
2865+
def _repr_(self) -> str:
28662866
"""
28672867
Return a string representation of the compound statistic.
28682868

src/sage/geometry/lattice_polytope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5060,7 +5060,7 @@ def _palp(command, polytopes, reduce_dimension=False):
50605060
for p in polytopes:
50615061
if p.dim() == 0:
50625062
raise ValueError(("Cannot run \"%s\" for the zero-dimensional "
5063-
+ "polytope!\nPolytope: %s") % (command, p))
5063+
+ "polytope!\nPolytope: %s") % (command, p))
50645064
if p.dim() < p.lattice_dim():
50655065
if not reduce_dimension:
50665066
raise ValueError(("Cannot run PALP for a %d-dimensional polytope " +
@@ -5075,9 +5075,9 @@ def _palp(command, polytopes, reduce_dimension=False):
50755075
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
50765076
stderr = p.stderr
50775077
err = stderr.read()
5078-
if len(err):
5078+
if err:
50795079
raise RuntimeError(("Error executing \"%s\" for a polytope sequence!"
5080-
+ "\nOutput:\n%s") % (command, err))
5080+
+ "\nOutput:\n%s") % (command, err))
50815081
os.remove(input_file_name)
50825082
try:
50835083
p.terminate()
@@ -5086,7 +5086,7 @@ def _palp(command, polytopes, reduce_dimension=False):
50865086
return output_file_name
50875087

50885088

5089-
def _palp_canonical_order(V, PM_max, permutations):
5089+
def _palp_canonical_order(V, PM_max, permutations) -> tuple:
50905090
r"""
50915091
Compute the PALP normal form of the vertices V
50925092
using auxiliary data computed elsewhere.

src/sage/schemes/elliptic_curves/cm.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def cm_orders(h, proof=None):
529529
# WAS extracted this by cutting/pasting from the pdf, and running this program:
530530
# z = {}
531531
# for X in open('/Users/wstein/tmp/a.txt').readlines():
532-
# if len(X.strip()):
532+
# if X.strip():
533533
# v = [int(a) for a in X.split()]
534534
# for i in range(5):
535535
# z[v[3*i]]=(v[3*i+2], v[3*i+1])
@@ -575,7 +575,7 @@ def cm_orders(h, proof=None):
575575

576576
# klaise_table = {}
577577
# for X in open('klaise_table.txt').readlines():
578-
# if len(X.strip()):
578+
# if X.strip():
579579
# v = [int(a) for a in X.split()]
580580
# for i in range(4):
581581
# klaise_table[v[3*i]]=(v[3*i+2], v[3*i+1])
@@ -888,7 +888,8 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
888888

889889
@cached_function
890890
def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
891-
r"""Return whether or not this is a CM `j`-invariant, and the CM discriminant if it is.
891+
r"""
892+
Return whether or not this is a CM `j`-invariant, and the CM discriminant if it is.
892893
893894
INPUT:
894895
@@ -910,7 +911,7 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
910911
ALGORITHM:
911912
912913
The default algorithm used is to test whether the minimal
913-
polynomial of ``j`` is a Hilbert CLass Polynomail, using
914+
polynomial of ``j`` is a Hilbert CLass Polynomial, using
914915
:func:`is_HCP` which implements Algorithm 2 of [CreSuth2023]_ by
915916
Cremona and Sutherland.
916917

src/sage/symbolic/ginac/inifcns_comb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static ex binomial_evalf(const ex & x, const ex & y, PyObject* parent)
105105
return binomial(x, y).hold();
106106
}
107107

108-
// At the moment the numeric evaluation of a binomail function always
108+
// At the moment the numeric evaluation of a binomial function always
109109
// gives a real number, but if this would be implemented using the gamma
110110
// function, also complex conjugation should be changed (or rather, deleted).
111111
static ex binomial_conjugate(const ex & x, const ex & y)

src/sage/symbolic/relation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ def has_integer_assumption(v) -> bool:
14181418
return any(isinstance(a, GenericDeclaration) and a.has(v) and
14191419
a._assumption in ['even', 'odd', 'integer', 'integervalued']
14201420
for a in alist)
1421-
if len(f.variables()) and all(has_integer_assumption(var) for var in f.variables()):
1421+
if f.variables() and all(has_integer_assumption(var) for var in f.variables()):
14221422
return f.solve_diophantine(x, solution_dict=solution_dict)
14231423

14241424
if algorithm == 'sympy':

src/sage/topology/simplicial_complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ def chain_complex(self, subcomplex=None, augmented=False,
21982198
# nonzero via a dictionary.
21992199
matrix_data = {}
22002200
col = 0
2201-
if len(old) and len(current):
2201+
if old and current:
22022202
for simplex in current:
22032203
for i in range(n + 1):
22042204
face_i = simplex.face(i)

0 commit comments

Comments
 (0)