Skip to content

Commit 1b02deb

Browse files
author
Release Manager
committed
gh-37229: some pep8 fixes in coding, in particular E275 this fixes various pycodestyle warnings in coding, in particular E275 `E275 missing whitespace after keyword` ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #37229 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 6b3e764 + e387d2e commit 1b02deb

File tree

8 files changed

+100
-101
lines changed

8 files changed

+100
-101
lines changed

src/sage/coding/abstract_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _explain_constructor(cl):
128128
var = "It accepts unspecified arguments as well.\n"
129129
else:
130130
var = ""
131-
return("{}\n{}\n{}See the documentation of {}.{} for more details."
131+
return ("{}\n{}\n{}See the documentation of {}.{} for more details."
132132
.format(reqs, opts, var, cl.__module__, cl.__name__))
133133

134134

src/sage/coding/code_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _check_n_q_d(n, q, d, field_based=True):
221221
raise ValueError("The alphabet size must be an integer >1")
222222
if field_based and not is_prime_power(q):
223223
raise ValueError("The alphabet size does not make sense for a code over a field")
224-
if not(0 < d <= n and n in ZZ and d in ZZ):
224+
if not (0 < d <= n and n in ZZ and d in ZZ):
225225
raise ValueError("The length or minimum distance does not make sense")
226226
return True
227227

src/sage/coding/cyclic_code.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,16 +577,17 @@ def field_embedding(self):
577577
To: Finite Field in z3 of size 2^3
578578
Defn: 1 |--> 1
579579
"""
580-
if not(hasattr(self, "_field_embedding")):
580+
if not hasattr(self, "_field_embedding"):
581581
self.defining_set()
582582
return self._field_embedding
583583

584584
def defining_set(self, primitive_root=None):
585585
r"""
586586
Return the set of exponents of the roots of ``self``'s generator
587-
polynomial over the extension field. Of course, it depends on the
588-
choice of the primitive root of the splitting field.
587+
polynomial over the extension field.
589588
589+
Of course, it depends on the choice of the primitive root of
590+
the splitting field.
590591
591592
INPUT:
592593

src/sage/coding/grs_code.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ def __eq__(self, other):
258258
True
259259
"""
260260
return isinstance(other, GeneralizedReedSolomonCode) \
261-
and self.base_field() == other.base_field() \
262-
and self.length() == other.length() \
263-
and self.dimension() == other.dimension() \
264-
and self.evaluation_points() == other.evaluation_points() \
265-
and self.column_multipliers() == other.column_multipliers()
261+
and self.base_field() == other.base_field() \
262+
and self.length() == other.length() \
263+
and self.dimension() == other.dimension() \
264+
and self.evaluation_points() == other.evaluation_points() \
265+
and self.column_multipliers() == other.column_multipliers()
266266

267267
def __hash__(self):
268268
"""
@@ -298,9 +298,9 @@ def _repr_(self):
298298
[40, 12, 29] Generalized Reed-Solomon Code over GF(59)
299299
"""
300300
return "[%s, %s, %s] %sReed-Solomon Code over GF(%s)"\
301-
% (self.length(), self.dimension(), self.minimum_distance(),
302-
"Generalized " if self.is_generalized() else "",
303-
self.base_field().cardinality())
301+
% (self.length(), self.dimension(), self.minimum_distance(),
302+
"Generalized " if self.is_generalized() else "",
303+
self.base_field().cardinality())
304304

305305
def _latex_(self):
306306
r"""
@@ -319,9 +319,9 @@ def _latex_(self):
319319
[40, 12, 29] \textnormal{ Generalized Reed-Solomon Code over } \Bold{F}_{59}
320320
"""
321321
return "[%s, %s, %s] \\textnormal{ %sReed-Solomon Code over } %s"\
322-
% (self.length(), self.dimension(), self.minimum_distance(),
323-
"Generalized " if self.is_generalized() else "",
324-
self.base_field()._latex_())
322+
% (self.length(), self.dimension(), self.minimum_distance(),
323+
"Generalized " if self.is_generalized() else "",
324+
self.base_field()._latex_())
325325

326326
def minimum_distance(self):
327327
r"""
@@ -390,7 +390,7 @@ def is_generalized(self):
390390
sage: C2.is_generalized()
391391
True
392392
"""
393-
return not all( beta.is_one() for beta in self.column_multipliers() )
393+
return not all(beta.is_one() for beta in self.column_multipliers())
394394

395395
@cached_method
396396
def multipliers_product(self):
@@ -538,7 +538,7 @@ def weight_distribution(self):
538538
q = self.base_ring().order()
539539
s = SR.var('s')
540540
wd = [1] + [0] * (d - 1)
541-
for i in range(d, n+1):
541+
for i in range(d, n + 1):
542542
tmp = binomial(n, i) * (q - 1)
543543
wd.append(tmp * symbolic_sum(binomial(i-1, s) * (-1)**s * q**(i - d - s), s, 0, i-d))
544544
return wd
@@ -647,9 +647,9 @@ def ReedSolomonCode(base_field, length, dimension, primitive_root=None):
647647
else:
648648
if primitive_root.multiplicative_order() != length:
649649
raise ValueError("Supplied primitive_root is not a primitive n'th root of unity")
650-
return GeneralizedReedSolomonCode([ primitive_root**i for i in range(length) ], dimension)
650+
return GeneralizedReedSolomonCode([primitive_root**i for i in range(length)], dimension)
651651

652-
####################### encoders ###############################
652+
# ###################### encoders ###############################
653653

654654

655655
class GRSEvaluationVectorEncoder(Encoder):
@@ -723,7 +723,7 @@ def __eq__(self, other):
723723
False
724724
"""
725725
return isinstance(other, GRSEvaluationVectorEncoder) \
726-
and self.code() == other.code()
726+
and self.code() == other.code()
727727

728728
def _repr_(self):
729729
r"""
@@ -788,7 +788,7 @@ def generator_matrix(self):
788788
C = self.code()
789789
alphas = C.evaluation_points()
790790
col_mults = C.column_multipliers()
791-
g = matrix(C.base_field(), C.dimension(), C.length(), lambda i,j: col_mults[j] * alphas[j]**i)
791+
g = matrix(C.base_field(), C.dimension(), C.length(), lambda i, j: col_mults[j] * alphas[j]**i)
792792
g.set_immutable()
793793
return g
794794

@@ -1086,7 +1086,7 @@ def message_space(self):
10861086
polynomial_ring = message_space
10871087

10881088

1089-
####################### decoders ###############################
1089+
# ###################### decoders ###############################
10901090

10911091

10921092
class GRSBerlekampWelchDecoder(Decoder):
@@ -1184,7 +1184,7 @@ def _latex_(self):
11841184
\textnormal{ Reed-Solomon Code over } \Bold{F}_{59}
11851185
"""
11861186
return "\\textnormal{Berlekamp Welch decoder for }%s"\
1187-
% self.code()._latex_()
1187+
% self.code()._latex_()
11881188

11891189
def _decode_to_code_and_message(self, r):
11901190
r"""
@@ -1229,14 +1229,15 @@ def _decode_to_code_and_message(self, r):
12291229
col_mults = C.column_multipliers()
12301230

12311231
r_list = copy(r)
1232-
r_list = [r[i]/col_mults[i] for i in range(0, C.length())]
1233-
1234-
t = (C.minimum_distance()-1) // 2
1235-
l0 = n-1-t
1236-
l1 = n-1-t-(k-1)
1237-
S = matrix(C.base_field(), n, l0+l1+2,
1238-
lambda i, j: (C.evaluation_points()[i])**j if j < (l0+1)
1239-
else r_list[i]*(C.evaluation_points()[i])**(j-(l0+1)))
1232+
r_list = [r[i] / col_mults[i] for i in range(C.length())]
1233+
1234+
t = (C.minimum_distance() - 1) // 2
1235+
l0 = n - 1 - t
1236+
l1 = n - t - k
1237+
pts = C.evaluation_points()
1238+
S = matrix(C.base_field(), n, l0 + l1 + 2,
1239+
lambda i, j: (pts[i]**j if j < (l0 + 1)
1240+
else r_list[i] * pts[i]**(j - (l0 + 1))))
12401241
S = S.right_kernel()
12411242
S = S.basis_matrix().row(0)
12421243
R = C.base_field()['x']
@@ -1574,7 +1575,7 @@ def _partial_xgcd(self, a, b, PolRing):
15741575

15751576
r = b
15761577
prev_r = a
1577-
while(r.degree() >= stop):
1578+
while r.degree() >= stop:
15781579
q = prev_r.quo_rem(r)[0]
15791580
(prev_r, r) = (r, prev_r - q * r)
15801581
(prev_s, s) = (s, prev_s - q * s)
@@ -1858,9 +1859,9 @@ def __eq__(self, other):
18581859
False
18591860
"""
18601861
return isinstance(other, GRSErrorErasureDecoder) \
1861-
and self.code() == other.code()
1862+
and self.code() == other.code()
18621863

1863-
def _repr_(self):
1864+
def _repr_(self) -> str:
18641865
r"""
18651866
Return a string representation of ``self``.
18661867
@@ -1890,7 +1891,7 @@ def _latex_(self):
18901891
\textnormal{ Reed-Solomon Code over } \Bold{F}_{59}
18911892
"""
18921893
return "\\textnormal{Error-Erasure decoder for }%s"\
1893-
% self.code()._latex_()
1894+
% self.code()._latex_()
18941895

18951896
def decode_to_message(self, word_and_erasure_vector):
18961897
r"""
@@ -2095,8 +2096,8 @@ def __eq__(self, other):
20952096
False
20962097
"""
20972098
return isinstance(other, GRSKeyEquationSyndromeDecoder) \
2098-
and self.code() == other.code()\
2099-
and self.input_space() == other.input_space()
2099+
and self.code() == other.code()\
2100+
and self.input_space() == other.input_space()
21002101

21012102
def _repr_(self):
21022103
r"""
@@ -2165,7 +2166,7 @@ def _partial_xgcd(self, a, b, PolRing):
21652166
prev_r = a
21662167
r = b
21672168

2168-
while(r.degree() >= t.degree()):
2169+
while r.degree() >= t.degree():
21692170
q = prev_r.quo_rem(r)[0]
21702171
prev_r, r = r, prev_r - q * r
21712172
prev_t, t = t, prev_t - q * t
@@ -2376,10 +2377,10 @@ def decoding_radius(self):
23762377
sage: D.decoding_radius()
23772378
14
23782379
"""
2379-
return (self.code().minimum_distance()-1) // 2
2380+
return (self.code().minimum_distance() - 1) // 2
23802381

23812382

2382-
####################### registration ###############################
2383+
# ###################### registration ###############################
23832384

23842385
GeneralizedReedSolomonCode._registered_encoders["EvaluationVector"] = GRSEvaluationVectorEncoder
23852386
GeneralizedReedSolomonCode._registered_encoders["EvaluationPolynomial"] = GRSEvaluationPolynomialEncoder

0 commit comments

Comments
 (0)