Skip to content

Commit c5c7d0b

Browse files
author
Release Manager
committed
gh-40027: fix pep E228 in all cython files in rings so just adding space around modulo where it was missing as suggested by `cython-lint` ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40027 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 15a83e1 + 113e679 commit c5c7d0b

22 files changed

+128
-121
lines changed

src/sage/rings/complex_mpc.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ cdef class MPComplexField_class(Field):
344344
z.init = 1
345345
return z
346346

347-
def _repr_ (self):
347+
def _repr_ (self) -> str:
348348
"""
349349
Return a string representation of ``self``.
350350

@@ -353,12 +353,12 @@ cdef class MPComplexField_class(Field):
353353
sage: MPComplexField(200, 'RNDDU') # indirect doctest
354354
Complex Field with 200 bits of precision and rounding RNDDU
355355
"""
356-
s = "Complex Field with %s bits of precision"%self._prec
356+
s = "Complex Field with %s bits of precision" % self._prec
357357
if self.__rnd != MPC_RNDNN:
358-
s = s + " and rounding %s"%(self.__rnd_str)
358+
s = s + " and rounding %s" % (self.__rnd_str)
359359
return s
360360

361-
def _latex_(self):
361+
def _latex_(self) -> str:
362362
r"""
363363
Return a latex representation of ``self``.
364364

@@ -613,7 +613,7 @@ cdef class MPComplexField_class(Field):
613613
sage: C = MPComplexField(10, 'RNDNZ'); C.name()
614614
'MPComplexField10_RNDNZ'
615615
"""
616-
return "MPComplexField%s_%s"%(self._prec, self.__rnd_str)
616+
return "MPComplexField%s_%s" % (self._prec, self.__rnd_str)
617617

618618
def __hash__(self):
619619
"""

src/sage/rings/complex_mpfr.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ class ComplexField_class(sage.rings.abc.ComplexField):
619619
return self._generic_coerce_map(S)
620620
return self._coerce_map_via([CLF], S)
621621

622-
def _repr_(self):
622+
def _repr_(self) -> str:
623623
"""
624624
Return a string representation of ``self``.
625625

@@ -630,9 +630,9 @@ class ComplexField_class(sage.rings.abc.ComplexField):
630630
sage: ComplexField(15) # indirect doctest
631631
Complex Field with 15 bits of precision
632632
"""
633-
return "Complex Field with %s bits of precision"%self._prec
633+
return "Complex Field with %s bits of precision" % self._prec
634634

635-
def _latex_(self):
635+
def _latex_(self) -> str:
636636
r"""
637637
Return a latex representation of ``self``.
638638

src/sage/rings/factorint.pyx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ cpdef aurifeuillian(n, m, F=None, bint check=True):
9191
cdef Py_ssize_t y = euler_phi(2*n)//2
9292
if F is None:
9393
from sage.rings.polynomial.cyclotomic import cyclotomic_value
94-
if n%2:
95-
if n%4 == 3:
94+
if n % 2:
95+
if n % 4 == 3:
9696
s = -1
9797
else:
9898
s = 1
@@ -196,7 +196,7 @@ cpdef factor_aurifeuillian(n, check=True):
196196
F = aurifeuillian(a, m, check=False)
197197
rem = prod(F)
198198
if check and not rem.divides(n):
199-
raise RuntimeError("rem=%s, F=%s, n=%s, m=%s"%(rem, F, n, m))
199+
raise RuntimeError(f"rem={rem}, F={F}, n={n}, m={m}")
200200
rem = n // rem
201201
if rem != 1:
202202
return [rem] + F
@@ -207,9 +207,10 @@ cpdef factor_aurifeuillian(n, check=True):
207207
def factor_cunningham(m, proof=None):
208208
r"""
209209
Return factorization of ``self`` obtained using trial division
210-
for all primes in the so called Cunningham table. This is
211-
efficient if ``self`` has some factors of type `b^n+1` or `b^n-1`,
212-
with `b` in `\{2,3,5,6,7,10,11,12\}`.
210+
for all primes in the so called Cunningham table.
211+
212+
This is efficient if ``self`` has some factors of type `b^n+1` or
213+
`b^n-1`, with `b` in `\{2,3,5,6,7,10,11,12\}`.
213214
214215
You need to install an optional package to use this method,
215216
this can be done with the following command line:

src/sage/rings/finite_rings/element_ntl_gf2e.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ cdef class FiniteField_ntl_gf2eElement(FinitePolyExtElement):
517517
y._cache = self._cache
518518
return y
519519

520-
def __repr__(FiniteField_ntl_gf2eElement self):
520+
def __repr__(FiniteField_ntl_gf2eElement self) -> str:
521521
"""
522522
Polynomial representation of ``self``.
523523

@@ -552,11 +552,11 @@ cdef class FiniteField_ntl_gf2eElement(FinitePolyExtElement):
552552
for i from 1 < i <= GF2X_deg(rep):
553553
c = GF2X_coeff(rep, i)
554554
if not GF2_IsZero(c):
555-
_repr.append("%s^%d"%(name,i))
555+
_repr.append("%s^%d" % (name, i))
556556

557557
return " + ".join(reversed(_repr))
558558

559-
def __bool__(FiniteField_ntl_gf2eElement self):
559+
def __bool__(FiniteField_ntl_gf2eElement self) -> bool:
560560
r"""
561561
Return ``True`` if ``self != k(0)``.
562562

src/sage/rings/finite_rings/element_pari_ffelt.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,11 +1412,11 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement):
14121412
raise TypeError("order must be at most 65536")
14131413

14141414
if self == 0:
1415-
return '0*Z(%s)'%F.order()
1415+
return '0*Z(%s)' % F.order()
14161416
assert F.degree() > 1
14171417
g = F.multiplicative_generator()
14181418
n = self.log(g)
1419-
return 'Z(%s)^%s'%(F.order(), n)
1419+
return 'Z(%s)^%s' % (F.order(), n)
14201420

14211421

14221422
def unpickle_FiniteFieldElement_pari_ffelt(parent, elem):

src/sage/rings/finite_rings/finite_field_base.pyx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ cdef class FiniteField(Field):
139139
else:
140140
return NotImplemented
141141

142-
def is_perfect(self):
142+
def is_perfect(self) -> bool:
143143
r"""
144144
Return whether this field is perfect, i.e., every element has a `p`-th
145145
root. Always returns ``True`` since finite fields are perfect.
@@ -151,7 +151,7 @@ cdef class FiniteField(Field):
151151
"""
152152
return True
153153

154-
def __repr__(self):
154+
def __repr__(self) -> str:
155155
"""
156156
String representation of this finite field.
157157

@@ -174,11 +174,13 @@ cdef class FiniteField(Field):
174174
Finite Field in d of size 7^20
175175
"""
176176
if self.degree()>1:
177-
return "Finite Field in %s of size %s^%s"%(self.variable_name(),self.characteristic(),self.degree())
177+
return "Finite Field in %s of size %s^%s" % (self.variable_name(),
178+
self.characteristic(),
179+
self.degree())
178180
else:
179-
return "Finite Field of size %s"%(self.characteristic())
181+
return "Finite Field of size %s" % (self.characteristic())
180182

181-
def _latex_(self):
183+
def _latex_(self) -> str:
182184
r"""
183185
Return a string denoting the name of the field in LaTeX.
184186

@@ -199,12 +201,12 @@ cdef class FiniteField(Field):
199201
\Bold{F}_{3}
200202
"""
201203
if self.degree() > 1:
202-
e = "^{%s}"%self.degree()
204+
e = "^{%s}" % self.degree()
203205
else:
204206
e = ""
205-
return "\\Bold{F}_{%s%s}"%(self.characteristic(), e)
207+
return "\\Bold{F}_{%s%s}" % (self.characteristic(), e)
206208

207-
def _gap_init_(self):
209+
def _gap_init_(self) -> str:
208210
"""
209211
Return string that initializes the GAP version of
210212
this finite field.
@@ -214,7 +216,7 @@ cdef class FiniteField(Field):
214216
sage: GF(9,'a')._gap_init_()
215217
'GF(9)'
216218
"""
217-
return 'GF(%s)'%self.order()
219+
return 'GF(%s)' % self.order()
218220

219221
def _magma_init_(self, magma):
220222
"""
@@ -234,10 +236,10 @@ cdef class FiniteField(Field):
234236
a
235237
"""
236238
if self.degree() == 1:
237-
return 'GF(%s)'%self.order()
239+
return 'GF(%s)' % self.order()
238240
B = self.base_ring()
239241
p = self.polynomial()
240-
s = "ext<%s|%s>"%(B._magma_init_(magma),p._magma_init_(magma))
242+
s = "ext<%s|%s>" % (B._magma_init_(magma),p._magma_init_(magma))
241243
return magma._with_names(s, self.variable_names())
242244

243245
def _macaulay2_init_(self, macaulay2=None):

src/sage/rings/finite_rings/integer_mod.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
546546
# Interfaces
547547
#################################################################
548548
def _pari_init_(self):
549-
return 'Mod(%s,%s)'%(str(self), self._modulus.sageInteger)
549+
return 'Mod(%s,%s)' % (str(self), self._modulus.sageInteger)
550550

551551
def __pari__(self):
552552
return self.lift().__pari__().Mod(self._modulus.sageInteger)
@@ -584,7 +584,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
584584
sage: b^2
585585
1
586586
"""
587-
return '%s!%s'%(self.parent()._magma_init_(magma), self)
587+
return '%s!%s' % (self.parent()._magma_init_(magma), self)
588588

589589
def _axiom_init_(self):
590590
"""
@@ -607,7 +607,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
607607
sage: aa.typeOf() # optional - fricas
608608
IntegerMod(15)
609609
"""
610-
return '%s :: %s'%(self, self.parent()._axiom_init_())
610+
return '%s :: %s' % (self, self.parent()._axiom_init_())
611611

612612
_fricas_init_ = _axiom_init_
613613

@@ -1784,9 +1784,9 @@ cdef class IntegerMod_abstract(FiniteRingElement):
17841784
n = self._modulus.sageInteger
17851785
return sage.rings.integer.Integer(n // self.lift().gcd(n))
17861786

1787-
def is_primitive_root(self):
1787+
def is_primitive_root(self) -> bool:
17881788
"""
1789-
Determines whether this element generates the group of units modulo n.
1789+
Determine whether this element generates the group of units modulo n.
17901790

17911791
This is only possible if the group of units is cyclic, which occurs if
17921792
n is 2, 4, a power of an odd prime or twice a power of an odd prime.
@@ -1894,7 +1894,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
18941894
try:
18951895
return sage.rings.integer.Integer(self.__pari__().znorder())
18961896
except PariError:
1897-
raise ArithmeticError("multiplicative order of %s not defined since it is not a unit modulo %s"%(
1897+
raise ArithmeticError("multiplicative order of %s not defined since it is not a unit modulo %s" % (
18981898
self, self._modulus.sageInteger))
18991899
19001900
def valuation(self, p):

src/sage/rings/finite_rings/residue_field.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ class ResidueField_generic(Field):
710710
OK = OK.ring_of_integers()
711711
return self.base_ring().has_coerce_map_from(R) or OK.has_coerce_map_from(R)
712712

713-
def __repr__(self):
713+
def __repr__(self) -> str:
714714
"""
715715
Return a string describing this residue field.
716716

@@ -733,8 +733,8 @@ class ResidueField_generic(Field):
733733
Univariate Polynomial Ring in t over Finite Field of size 17
734734
"""
735735
if self.p.ring() is ZZ:
736-
return "Residue field of Integers modulo %s"%self.p.gen()
737-
return "Residue field %sof %s"%('in %s '%self.gen() if self.degree() > 1 else '', self.p)
736+
return "Residue field of Integers modulo %s" % self.p.gen()
737+
return "Residue field %sof %s" % ('in %s ' % self.gen() if self.degree() > 1 else '', self.p)
738738

739739
def lift(self, x):
740740
"""

src/sage/rings/padics/padic_generic_element.pyx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ cdef class pAdicGenericElement(LocalGenericElement):
23632363
inner_sum = R.zero()
23642364
for u in range(upper_u,0,-1):
23652365
# We want u to be a p-adic unit
2366-
if u%p==0:
2366+
if u % p == 0:
23672367
new_term = R.zero()
23682368
else:
23692369
new_term = ~R(u)
@@ -2970,8 +2970,8 @@ cdef class pAdicGenericElement(LocalGenericElement):
29702970
# we compute the value of N! as we go through the loop
29712971
nfactorial_unit,nfactorial_val = R.one(),0
29722972
2973-
nmodp = N%p
2974-
for n in range(N,0,-1):
2973+
nmodp = N % p
2974+
for n in range(N, 0, -1):
29752975
# multiply everything by x
29762976
series_val += x_val
29772977
series_unit *= x_unit
@@ -4224,7 +4224,7 @@ cdef class pAdicGenericElement(LocalGenericElement):
42244224
n = Integer(n)
42254225
42264226
if z.valuation() < 0:
4227-
verbose("residue oo, using functional equation for reciprocal. %d %s"%(n,str(self)), level=2)
4227+
verbose("residue oo, using functional equation for reciprocal. %d %s" % (n, str(self)), level=2)
42284228
return (-1)**(n+1)*(1/z).polylog(n)-(z.log(p_branch)**n)/K(n.factorial())
42294229
42304230
zeta = K.teichmuller(z)
@@ -4233,7 +4233,7 @@ cdef class pAdicGenericElement(LocalGenericElement):
42334233
if zeta == 0:
42344234
if z.precision_absolute() == PlusInfinity():
42354235
return K(0)
4236-
verbose("residue 0, using series. %d %s"%(n,str(self)), level=2)
4236+
verbose("residue 0, using series. %d %s" % (n, str(self)), level=2)
42374237
M = ceil((prec/z.valuation()).log(p).n())
42384238
N = prec - n*M
42394239
ret = K(0)
@@ -4247,7 +4247,7 @@ cdef class pAdicGenericElement(LocalGenericElement):
42474247
if zeta == 1:
42484248
if z == 1:
42494249
return Integer(2)**(n-1)*K(-1).polylog(n, p_branch=p_branch)/(1-Integer(2)**(n-1))
4250-
verbose("residue 1, using _polylog_res_1. %d %s"%(n,str(self)), level=2)
4250+
verbose("residue 1, using _polylog_res_1. %d %s" % (n, str(self)), level=2)
42514251
return self._polylog_res_1(n, p_branch)
42524252
42534253
# Set up precision bounds
@@ -4261,7 +4261,7 @@ cdef class pAdicGenericElement(LocalGenericElement):
42614261
K = Qp(p, prec)
42624262
42634263
# Residue disk around zeta
4264-
verbose("general case. %d %s"%(n, str(self)), level=2)
4264+
verbose("general case. %d %s" % (n, str(self)), level=2)
42654265
Li_i_zeta = [0] + [p**i/(p**i-1)*gtr[i](1/(1-zeta)) for i in range(1,n+1)]
42664266
42674267
T = PowerSeriesRing(K, default_prec=ceil(tsl), names='t')
@@ -4616,7 +4616,8 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs):
46164616
k = r1 % p
46174617
r1 = (r1 + k * q1) // p
46184618
if use_longs: # Use Dwork expansion to compute p-adic Gamma
4619-
s1 *= -evaluate_dwork_mahler_long(vv, r1*r2%q3, p, bd, k, q3)
4619+
s1 *= -evaluate_dwork_mahler_long(vv, r1*r2 % q3,
4620+
p, bd, k, q3)
46204621
s1 %= q3
46214622
else:
46224623
s *= -evaluate_dwork_mahler(v, R1(r1)*d, p, bd, k)

0 commit comments

Comments
 (0)