Skip to content

Commit 2be2d84

Browse files
author
Release Manager
committed
gh-38740: fixing some suggestions by ruff some by hand, some scripted in particular, removal of useless parentheses ### 📝 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: #38740 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Kwankyu Lee
2 parents 9ea0310 + a5489f7 commit 2be2d84

File tree

94 files changed

+196
-205
lines changed

Some content is hidden

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

94 files changed

+196
-205
lines changed

src/sage/categories/examples/commutative_additive_semigroups.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,10 @@ def __init__(self, parent, iterable):
166166
{'a': 2, 'b': 0, 'c': 1, 'd': 5}
167167
"""
168168
d = {a: 0 for a in parent.alphabet}
169-
for a, c in iterable:
170-
d[a] = c
169+
d.update(iterable)
171170
ElementWrapper.__init__(self, parent, d)
172171

173-
def _repr_(self):
172+
def _repr_(self) -> str:
174173
"""
175174
EXAMPLES::
176175
@@ -182,8 +181,9 @@ def _repr_(self):
182181
0
183182
"""
184183
d = self.value
185-
result = ' + '.join( ("%s*%s" % (d[a],a) if d[a] != 1 else a) for a in sorted(d.keys()) if d[a] != 0)
186-
return '0' if result == '' else result
184+
result = ' + '.join(("%s*%s" % (d[a], a) if d[a] != 1 else a)
185+
for a in sorted(d.keys()) if d[a] != 0)
186+
return '0' if not result else result
187187

188188
def __hash__(self):
189189
"""

src/sage/categories/pushout.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,13 +3055,11 @@ def merge(self, other):
30553055
codomain = self.codomain().join([self.codomain(), other.codomain()])
30563056
# Get the optional arguments:
30573057
as_field = self.as_field or other.as_field
3058-
kwds = {}
3059-
for k,v in self.kwds.items():
3060-
kwds[k] = v
3061-
for k,v in other.kwds.items():
3058+
kwds = dict(self.kwds)
3059+
for k, v in other.kwds.items():
30623060
if k == 'category':
30633061
if kwds[k] is not None:
3064-
kwds[k] = v.join([v,kwds[k]])
3062+
kwds[k] = v.join([v, kwds[k]])
30653063
else:
30663064
kwds[k] = v
30673065
continue

src/sage/coding/code_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def elias_bound_asymp(delta, q):
737737
0.39912396330...
738738
"""
739739
r = 1 - 1 / q
740-
return RDF((1-entropy(r-sqrt(r*(r-delta)), q)))
740+
return RDF(1-entropy(r-sqrt(r*(r-delta)), q))
741741

742742

743743
def mrrw1_bound_asymp(delta, q):

src/sage/coding/source_coding/huffman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def encode(self, string):
394394
'Sage is my most favorite general purpose computer algebra system'
395395
"""
396396
if self._character_to_code:
397-
return "".join((self._character_to_code[x] for x in string))
397+
return "".join(self._character_to_code[x] for x in string)
398398

399399
def decode(self, string):
400400
r"""

src/sage/combinat/interval_posets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,8 +3533,7 @@ def profil(gr, vertex):
35333533

35343534
liste = clockwise_labelling(graph0, -1)[1:]
35353535
relabelling = {l: i for i, l in enumerate(liste)}
3536-
for l in [-1, -2, -3]:
3537-
relabelling[l] = l
3536+
relabelling.update((i, i) for i in [-1, -2, -3])
35383537
new_graph = graph.relabel(relabelling, inplace=False)
35393538

35403539
dyckword_top = []

src/sage/combinat/root_system/type_reducible.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def inject_weights(self, i, v):
525525
[(1, 1, 0, 0, 0), (0, 0, 0, 1/2, 1/2)]
526526
"""
527527
shift = self.root_system.cartan_type()._shifts[i]
528-
return self._from_dict( dict([(shift+k, c) for (k,c) in v ]))
528+
return self._from_dict({shift + k: c for k, c in v})
529529

530530
@cached_method
531531
def simple_root(self, i):

src/sage/combinat/sf/sfa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ def _change_by_plethysm(self, x, expr, deg_one):
19821982
# Convert to the power sum
19831983
p = self.realization_of().power()
19841984
p_x = p(x)
1985-
expr_k = lambda k: expr.subs(**dict([(str(x),x**k) for x in deg_one]))
1985+
expr_k = lambda k: expr.subs(**{str(x): x**k for x in deg_one})
19861986
f = lambda m,c: (m, c*prod([expr_k(k) for k in m]))
19871987
return self(p_x.map_item(f))
19881988

src/sage/crypto/mq/rijndael_gf.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ def __call__(self, text, key, algorithm='encrypt', format='hex'):
613613
elif algorithm == 'decrypt':
614614
return self.decrypt(text, key, format)
615615
else:
616-
raise ValueError(("keyword 'algorithm' must be either 'encrypt' "
617-
"or 'decrypt'"))
616+
raise ValueError("keyword 'algorithm' must be either 'encrypt' "
617+
"or 'decrypt'")
618618

619619
def __repr__(self):
620620
r"""
@@ -981,8 +981,8 @@ def encrypt(self, plain, key, format='hex'):
981981
key_state = self._bin_to_GF(key)
982982
roundKeys = self.expand_key(key_state)
983983
else:
984-
raise ValueError(("'format' keyword must be either 'hex' or "
985-
"'binary'"))
984+
raise ValueError("'format' keyword must be either 'hex' or "
985+
"'binary'")
986986

987987
state = self.add_round_key(state, roundKeys[0])
988988
for r in range(self._Nr-1):
@@ -1057,8 +1057,8 @@ def decrypt(self, ciphertext, key, format='hex'):
10571057
elif format == 'binary':
10581058
if not isinstance(ciphertext, str) or \
10591059
any(c not in '01' for c in ciphertext):
1060-
raise TypeError(("'ciphertext' keyword must be a binary "
1061-
"string"))
1060+
raise TypeError("'ciphertext' keyword must be a binary "
1061+
"string")
10621062
if len(ciphertext) != 32 * self._Nb:
10631063
msg = "'ciphertext' keyword's length must be {0}, not {1}"
10641064
raise ValueError(msg.format(32 * self._Nb, len(ciphertext)))
@@ -1072,8 +1072,8 @@ def decrypt(self, ciphertext, key, format='hex'):
10721072
key_state = self._bin_to_GF(key)
10731073
roundKeys = self.expand_key(key_state)
10741074
else:
1075-
raise ValueError(("'format' keyword must be either \'hex\' or "
1076-
"'binary'"))
1075+
raise ValueError("'format' keyword must be either \'hex\' or "
1076+
"'binary'")
10771077

10781078
state = self.add_round_key(state, roundKeys[self._Nr])
10791079
state = self.shift_rows(state, algorithm='decrypt')
@@ -1874,8 +1874,8 @@ def _sub_bytes_pc(self, row, col, algorithm='encrypt', no_inversion=False):
18741874
else:
18751875
return result ** 254
18761876
else:
1877-
raise ValueError(("keyword 'algorithm' must be either 'encrypt' "
1878-
"or 'decrypt'"))
1877+
raise ValueError("keyword 'algorithm' must be either 'encrypt' "
1878+
"or 'decrypt'")
18791879

18801880
def _srd(self, el, algorithm='encrypt'):
18811881
r"""
@@ -1910,8 +1910,8 @@ def _srd(self, el, algorithm='encrypt'):
19101910
state = [el] + [self._F.zero()]*((4 * self._Nb)-1)
19111911
return p(state) ** 254
19121912
else:
1913-
raise ValueError(("keyword 'algorithm' must be either 'encrypt' "
1914-
"or 'decrypt'"))
1913+
raise ValueError("keyword 'algorithm' must be either 'encrypt' "
1914+
"or 'decrypt'")
19151915

19161916
def sub_bytes(self, state, algorithm='encrypt'):
19171917
r"""
@@ -2010,8 +2010,8 @@ def _mix_columns_pc(self, row, col, algorithm='encrypt'):
20102010
elif algorithm == 'decrypt':
20112011
coeffs = self._mixcols_D
20122012
else:
2013-
raise ValueError(("keyword 'algorithm' must be either 'encrypt' "
2014-
"or 'decrypt'"))
2013+
raise ValueError("keyword 'algorithm' must be either 'encrypt' "
2014+
"or 'decrypt'")
20152015
return sum([coeffs[row,k] * self.state_vrs[k,col] for k in range(4)])
20162016

20172017
def mix_columns(self, state, algorithm='encrypt'):
@@ -2109,8 +2109,8 @@ def _shift_rows_pc(self, row, col, algorithm='encrypt'):
21092109
elif algorithm == 'decrypt':
21102110
offs = self._shiftrows_offsets_D
21112111
else:
2112-
raise ValueError(("keyword 'algorithm' must be either 'encrypt' "
2113-
"or 'decrypt'"))
2112+
raise ValueError("keyword 'algorithm' must be either 'encrypt' "
2113+
"or 'decrypt'")
21142114
return self.state_vrs[row, (col + offs[4 - self._Nb][row]) % 4]
21152115

21162116
def shift_rows(self, state, algorithm='encrypt'):

src/sage/data_structures/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
lazy_import('sage.combinat.sf.sfa', ['_variables_recursive', '_raise_variables'])
108108

109109

110-
class Stream():
110+
class Stream:
111111
"""
112112
Abstract base class for all streams.
113113
@@ -2410,7 +2410,7 @@ def stretched_power_restrict_degree(self, i, m, d):
24102410
_raise_variables(c, i, self._degree_one)
24112411
for mon, c in power_d}
24122412
else:
2413-
terms = {tuple((mu.stretch(i) for mu in mon)):
2413+
terms = {tuple(mu.stretch(i) for mu in mon):
24142414
_raise_variables(c, i, self._degree_one)
24152415
for mon, c in power_d}
24162416
return self._basis(self._p.element_class(self._p, terms))

src/sage/databases/cremona.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,10 @@ def iter_optimal(self, conductors):
11221122
if N == 990:
11231123
for c in self.__connection__.cursor().execute('SELECT class '
11241124
+ 'FROM t_class WHERE conductor=990'):
1125-
if c[0][-1] == u'h':
1126-
yield self.elliptic_curve(c[0]+u'3')
1125+
if c[0][-1] == 'h':
1126+
yield self.elliptic_curve(c[0]+'3')
11271127
else:
1128-
yield self.elliptic_curve(c[0]+u'1')
1128+
yield self.elliptic_curve(c[0]+'1')
11291129
continue
11301130
for c in self.__connection__.cursor().execute('SELECT curve '
11311131
+ 'FROM t_curve,t_class USING(class) WHERE curve=class||1 '

src/sage/databases/findstat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4352,7 +4352,7 @@ def first_terms(self, function, level=None):
43524352
g = (x for x in self._sageconstructor_overridden
43534353
if self.element_level(x) == level)
43544354

4355-
return lazy_list(((x, function(x)) for x in g))
4355+
return lazy_list((x, function(x)) for x in g)
43564356

43574357
def id(self):
43584358
r"""

src/sage/databases/sql_db.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def construct_skeleton(database):
254254
exe1 = cur.execute("PRAGMA table_info(%s)" % table[0])
255255
for col in exe1.fetchall():
256256
if not col[2]:
257-
typ = u'NOTYPE'
257+
typ = 'NOTYPE'
258258
else:
259259
typ = col[2]
260260
skeleton[table[0]][col[1]] = {'sql':typ,
@@ -482,7 +482,7 @@ def __init__(self, database, *args, **kwds):
482482
else:
483483
self.__query_string__ = kwds['query_string']
484484
if 'param_tuple' in kwds:
485-
self.__param_tuple__ = tuple((str(x) for x in kwds['param_tuple']))
485+
self.__param_tuple__ = tuple(str(x) for x in kwds['param_tuple'])
486486
else:
487487
self.__param_tuple__ = tuple()
488488
return
@@ -2164,7 +2164,7 @@ def add_rows(self, table_name, rows, entry_order=None):
21642164
if self.__read_only__:
21652165
raise RuntimeError('Cannot add rows to read only database.')
21662166
quest = '(' + ', '.join('?' for i in rows[0]) + ')'
2167-
strows = [tuple((str(entry) for entry in row)) for row in rows]
2167+
strows = [tuple(str(entry) for entry in row) for row in rows]
21682168

21692169
if entry_order is not None:
21702170
self.__connection__.executemany('INSERT INTO ' + table_name

src/sage/doctest/control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def skipfile(filename, tested_optional_tags=False, *,
341341
return False
342342

343343

344-
class Logger():
344+
class Logger:
345345
r"""
346346
File-like object which implements writing to multiple files at
347347
once.

src/sage/doctest/external.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def external_software() -> list[str]:
379379
external_software = external_software()
380380

381381

382-
class AvailableSoftware():
382+
class AvailableSoftware:
383383
"""
384384
This class keeps the set of available software whose availability is detected lazily
385385
from the list of external software.

src/sage/doctest/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def sorted_pairs(iterable, pairs=False):
112112
return repr(val)
113113

114114

115-
class AttributeAccessTracerHelper():
115+
class AttributeAccessTracerHelper:
116116

117117
def __init__(self, delegate, prefix=" ", reads=True):
118118
r"""
@@ -223,7 +223,7 @@ def set(self, name, val):
223223
setattr(self.delegate, name, val)
224224

225225

226-
class AttributeAccessTracerProxy():
226+
class AttributeAccessTracerProxy:
227227

228228
def __init__(self, delegate, **kwds):
229229
r"""

src/sage/doctest/forker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ def kill(self):
24762476
return True
24772477

24782478

2479-
class DocTestTask():
2479+
class DocTestTask:
24802480
"""
24812481
This class encapsulates the tests from a single source.
24822482

src/sage/doctest/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def reduce_hex(fingerprints):
652652
return "%032x" % res
653653

654654

655-
class OriginalSource():
655+
class OriginalSource:
656656
r"""
657657
Context swapping out the pre-parsed source with the original for
658658
better reporting.

src/sage/doctest/sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def get_basename(path):
124124
return basename
125125

126126

127-
class DocTestSource():
127+
class DocTestSource:
128128
"""
129129
This class provides a common base class for different sources of doctests.
130130

src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def __call__(self, x, type_3_pole_check=True):
869869
else:
870870
new_poly.append(ring_of_integers(i).mod(ideal))
871871
new_poly = R(new_poly)
872-
fraction.append((new_poly))
872+
fraction.append(new_poly)
873873
gcd = fraction[0].gcd(fraction[1])
874874
num = fraction[0].quo_rem(gcd)[0]
875875
dem = fraction[1].quo_rem(gcd)[0]

src/sage/dynamics/cellular_automata/glca.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,24 +363,24 @@ def _unicode_art_(self, number=None):
363363
number = len(self._states)
364364

365365
space = len(self._states[:number]) * 2 - 1
366-
ret = UnicodeArt([u' '*space + u'◾'])
366+
ret = UnicodeArt([' '*space + '◾'])
367367
space += 1
368368
for i,state in enumerate(self._states[:number]):
369-
temp = u' '*(space-2)
370-
last = u' '
369+
temp = ' '*(space-2)
370+
last = ' '
371371
for x in state:
372372
if x & 0x4:
373-
if last == u'╱':
374-
temp += u'╳'
373+
if last == '╱':
374+
temp += '╳'
375375
else:
376-
temp += u'╲'
376+
temp += '╲'
377377
else:
378378
temp += last
379-
temp += u'│' if x & 0x2 else ' '
380-
last = u'╱' if x & 0x1 else ' '
379+
temp += '│' if x & 0x2 else ' '
380+
last = '╱' if x & 0x1 else ' '
381381
ret *= UnicodeArt([temp + last])
382382
space -= 1
383-
ret *= UnicodeArt([u' '*space + u' '.join(u'◾' for dummy in range(2*i+1))])
383+
ret *= UnicodeArt([' '*space + ' '.join('◾' for dummy in range(2*i+1))])
384384
space -= 1
385385
return ret
386386

src/sage/dynamics/complex_dynamics/mandel_julia.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def external_ray(theta, **kwds):
430430
pixel[int(k[0]), int(k[1])] = tuple(ray_color)
431431
return M
432432

433+
433434
def kneading_sequence(theta):
434435
r"""
435436
Determines the kneading sequence for an angle theta in RR/ZZ which

src/sage/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def get_cblas_pc_module_name() -> str:
337337
"""
338338
import pkgconfig
339339
cblas_pc_modules = CBLAS_PC_MODULES.split(':')
340-
return next((blas_lib for blas_lib in cblas_pc_modules if pkgconfig.exists(blas_lib)))
340+
return next(blas_lib for blas_lib in cblas_pc_modules if pkgconfig.exists(blas_lib))
341341

342342

343343
default_required_modules = ('fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular',

src/sage/features/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def __str__(self):
467467
return "\n".join(lines)
468468

469469

470-
class FeatureTestResult():
470+
class FeatureTestResult:
471471
r"""
472472
The result of a :meth:`Feature.is_present` call.
473473

0 commit comments

Comments
 (0)