Skip to content

Commit e8304b8

Browse files
committed
activating more cython-lint checks
1 parent 618bedf commit e8304b8

16 files changed

+48
-46
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ build-backend = "mesonpy"
4141

4242
[tool.cython-lint]
4343
max-line-length = 120
44-
ignore = ['E114','E117','E127','E128','E129','E202','E221','E222','E231','E261','E262','E265','E501','E711','E722','E731','E741','E743']
44+
ignore = ['E128','E129','E221','E222','E261','E262','E265','E501','E731','E741','E743']
4545
exclude = 'src/flint/flintlib/.*'
4646

4747
[tool.spin]

src/flint/types/acb.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ cdef int acb_calc_func_callback(acb_ptr out, const acb_t inp, void * param, long
120120
if not typecheck(y, acb):
121121
raise TypeError("integrand must return an acb")
122122
acb_set(out, (<acb> y).val)
123-
except:
123+
except (TypeError, ValueError):
124124
import sys
125125
ictx.exn_type, ictx.exn_obj, ictx.exn_tb = sys.exc_info()
126126
acb_indeterminate(out)
@@ -1346,7 +1346,7 @@ cdef class acb(flint_scalar):
13461346
acb_hypgeom_gamma_upper((<acb>u).val, (<acb>s).val, (<acb>self).val, regularized, getprec())
13471347
return u
13481348

1349-
def gamma_lower(self,s, int regularized=0):
1349+
def gamma_lower(self, s, int regularized=0):
13501350
r"""
13511351
Lower incomplete gamma function `\gamma(s,z)`. The argument *z*
13521352
is given by *self* and the order *s* is passed as an extra parameter.

src/flint/types/acb_mat.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ cdef class acb_mat(flint_mat):
124124
acb_mat_init(self.val, m, n)
125125
for i from 0 <= i < m:
126126
for j from 0 <= j < n:
127-
x = acb(val[i,j])
127+
x = acb(val[i, j])
128128
acb_set(acb_mat_entry(self.val, i, j), (<acb>x).val)
129129
else:
130130
raise TypeError("cannot create acb_mat from input of type %s" % type(val))
@@ -137,7 +137,7 @@ cdef class acb_mat(flint_mat):
137137
if isinstance(entries, (int, float, complex, fmpz, fmpq, arb, acb)):
138138
c = entries
139139
entries = [0] * (m * n)
140-
for i in range(min(m,n)):
140+
for i in range(min(m, n)):
141141
entries[i*n + i] = c
142142
else:
143143
entries = list(entries)

src/flint/types/acb_series.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ cdef class acb_series(flint_series):
685685
cap = getcap()
686686
cap = min(cap, (<acb_series>s).prec)
687687
u = acb_series.__new__(acb_series)
688-
acb_hypgeom_airy_series(NULL, NULL, NULL, (<acb_series>u).val,(<acb_series>s).val, cap, getprec())
688+
acb_hypgeom_airy_series(NULL, NULL, NULL, (<acb_series>u).val,
689+
(<acb_series>s).val, cap, getprec())
689690
(<acb_series>u).prec = cap
690691
return u
691692

src/flint/types/arb_mat.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ cdef class arb_mat(flint_mat):
122122
arb_mat_init(self.val, m, n)
123123
for i from 0 <= i < m:
124124
for j from 0 <= j < n:
125-
x = arb(val[i,j])
125+
x = arb(val[i, j])
126126
arb_set(arb_mat_entry(self.val, i, j), (<arb>x).val)
127127
else:
128128
raise TypeError("cannot create arb_mat from input of type %s" % type(val))
@@ -135,7 +135,7 @@ cdef class arb_mat(flint_mat):
135135
if isinstance(entries, (int, float, fmpz, fmpq, arb)):
136136
c = entries
137137
entries = [0] * (m * n)
138-
for i in range(min(m,n)):
138+
for i in range(min(m, n)):
139139
entries[i*n + i] = c
140140
else:
141141
entries = list(entries)

src/flint/types/arb_series.pyx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ cdef class arb_series(flint_series):
668668
cap = getcap()
669669
cap = min(cap, (<arb_series>s).prec)
670670
u = arb_series.__new__(arb_series)
671-
arb_hypgeom_airy_series(NULL, NULL, NULL, (<arb_series>u).val,(<arb_series>s).val, cap, getprec())
671+
arb_hypgeom_airy_series(NULL, NULL, NULL, (<arb_series>u).val,
672+
(<arb_series>s).val, cap, getprec())
672673
(<arb_series>u).prec = cap
673674
return u
674675

@@ -813,7 +814,7 @@ cdef class arb_series(flint_series):
813814
try:
814815
roots = []
815816
ctx.cap = 1
816-
queue = [(arb(a),arb(b))]
817+
queue = [(arb(a), arb(b))]
817818
qvals = [(xsgn(f(arb_series(a))[0]), xsgn(f(arb_series(b))[0]))]
818819
if 0 in qvals[0]:
819820
raise ValueError("unknown sign at an endpoint; try a slightly larger interval")
@@ -833,8 +834,8 @@ cdef class arb_series(flint_series):
833834
#fa = xsgn(f(arb_series(a))[0])
834835
#fb = xsgn(f(arb_series(b))[0])
835836
ctx.cap = 2
836-
if fa * fb < 0 and f(arb_series([arb(m, r),1]))[1] != 0:
837-
roots.append((a,b))
837+
if fa * fb < 0 and f(arb_series([arb(m, r), 1]))[1] != 0:
838+
roots.append((a, b))
838839
continue
839840
ctx.cap = 1
840841
fm = xsgn(f(arb_series(m))[0])
@@ -843,10 +844,10 @@ cdef class arb_series(flint_series):
843844
fm = xsgn(f(arb_series(m))[0])
844845
if fm == 0:
845846
raise ValueError("unknown sign at a bisection point")
846-
queue.append((m,b))
847-
qvals.append((fm,fb))
848-
queue.append((a,m))
849-
qvals.append((fa,fm))
847+
queue.append((m, b))
848+
qvals.append((fm, fb))
849+
queue.append((a, m))
850+
qvals.append((fa, fm))
850851
finally:
851852
ctx.cap = orig_cap
852853
return roots

src/flint/types/dirichlet.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ cdef class dirichlet_char(object):
105105
_dirichlet_group_cache[q] = G
106106
self.G = G
107107
dirichlet_char_init(self.val, self.G.val)
108-
assert 1 <= l <= max(q,2)-1 and n_gcd(q, l) == 1
108+
assert 1 <= l <= max(q, 2)-1 and n_gcd(q, l) == 1
109109
dirichlet_char_log(self.val, self.G.val, l)
110110

111111
def group(self):

src/flint/types/fmpq_mat.pyx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from flint.types.fmpq cimport any_as_fmpq
55
from flint.types.fmpz cimport any_as_fmpz
66

77
from flint.flintlib.fmpz_mat cimport fmpz_mat_nrows, fmpz_mat_ncols
8-
from flint.flintlib.fmpq cimport fmpq_set,fmpq_numref, fmpq_denref
8+
from flint.flintlib.fmpq cimport fmpq_set, fmpq_numref, fmpq_denref
99
from flint.flintlib.fmpq_poly cimport fmpq_poly_init
1010
from flint.flintlib.fmpq_mat cimport *
1111

@@ -48,12 +48,14 @@ cdef class fmpq_mat(flint_mat):
4848
if len(args) == 1:
4949
val = args[0]
5050
if typecheck(val, fmpq_mat):
51-
fmpq_mat_init(self.val, fmpq_mat_nrows((<fmpq_mat>val).val),
52-
fmpq_mat_ncols((<fmpq_mat>val).val))
51+
fmpq_mat_init(self.val,
52+
fmpq_mat_nrows((<fmpq_mat>val).val),
53+
fmpq_mat_ncols((<fmpq_mat>val).val))
5354
fmpq_mat_set(self.val, (<fmpq_mat>val).val)
5455
elif typecheck(val, fmpz_mat):
55-
fmpq_mat_init(self.val, fmpz_mat_nrows((<fmpz_mat>val).val),
56-
fmpz_mat_ncols((<fmpz_mat>val).val))
56+
fmpq_mat_init(self.val,
57+
fmpz_mat_nrows((<fmpz_mat>val).val),
58+
fmpz_mat_ncols((<fmpz_mat>val).val))
5759
fmpq_mat_set_fmpz_mat(self.val, (<fmpz_mat>val).val)
5860
elif isinstance(val, (list, tuple)):
5961
m = len(val)

src/flint/types/fmpq_series.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from flint.types.acb_poly cimport acb_poly
1515
from flint.types.acb_series cimport acb_series
1616
from flint.types.fmpz cimport any_as_fmpz
1717

18-
from flint.flintlib.fmpz cimport fmpz_is_zero,fmpz_set,fmpz_equal
18+
from flint.flintlib.fmpz cimport fmpz_is_zero, fmpz_set, fmpz_equal
1919
from flint.flintlib.fmpq_poly cimport *
2020

2121
cdef fmpq_series_coerce_operands(x, y):

src/flint/types/fmpz_mat.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cdef class fmpz_mat(flint_mat):
8080
8181
"""
8282

83-
# cdef fmpz_mat_t val
83+
# cdef fmpz_mat_t val
8484

8585
def __cinit__(self):
8686
fmpz_mat_init(self.val, 0, 0)
@@ -651,7 +651,7 @@ cdef class fmpz_mat(flint_mat):
651651
if transform:
652652
v = fmpz_mat(self.nrows(), self.nrows())
653653
for 0 <= i < self.nrows():
654-
v[i,i] = 1
654+
v[i, i] = 1
655655
fmpz_lll(u.val, v.val, ctx)
656656
return u, v
657657
else:

src/flint/types/fmpz_mod.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,8 @@ cdef class fmpz_mod(flint_scalar):
400400
return NotImplemented
401401

402402
res = fmpz_equal(self.val, (<fmpz_mod>other).val) and \
403-
(self.ctx == (<fmpz_mod>other).ctx)
404-
if op == 2:
405-
return res
406-
else:
407-
return not res
403+
(self.ctx == (<fmpz_mod>other).ctx)
404+
return res if op == 2 else not res
408405

409406
def __bool__(self):
410407
return not self.is_zero()

src/flint/types/fmpz_mod_poly.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ cdef class fmpz_mod_poly(flint_poly):
11861186
# For larger exponents we need to cast e to an fmpz first
11871187
e_fmpz = any_as_fmpz(e)
11881188
if e_fmpz is NotImplemented:
1189-
raise TypeError(f"exponent cannot be cast to an fmpz type: {e = }")
1189+
raise TypeError(f"exponent cannot be cast to an fmpz type: {e=}")
11901190

11911191
# To optimise powering, we precompute the inverse of the reverse of the modulus
11921192
if mod_rev_inv is not None:
@@ -1716,7 +1716,7 @@ cdef class fmpz_mod_poly(flint_poly):
17161716
self.val, self.ctx.mod.val
17171717
)
17181718
if n > n_max:
1719-
raise ValueError(f"Cannot deflate with {n = }, maximum allowed value is {n_max = }")
1719+
raise ValueError(f"Cannot deflate with {n=}, maximum allowed value is {n_max=}")
17201720

17211721
res = self.ctx.new_ctype_poly()
17221722
fmpz_mod_poly_deflate(

src/flint/types/fq_default.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ cdef class fq_default_ctx:
5656

5757
# Now fq_type should be an int between 0, 5
5858
if not typecheck(fq_type, int):
59-
raise TypeError(f"{fq_type = } is invalid")
59+
raise TypeError(f"{fq_type=} is invalid")
6060
if fq_type < 0 or fq_type > 5:
61-
raise ValueError(f"{fq_type = } should be between 0 and 5")
61+
raise ValueError(f"{fq_type=} should be between 0 and 5")
6262

6363
return fq_type
6464

@@ -129,14 +129,14 @@ cdef class fq_default_ctx:
129129
# c_from_order expects the characteristic to be fmpz type
130130
prime = any_as_fmpz(p)
131131
if prime is NotImplemented:
132-
raise TypeError(f"cannot coerce {p = } to type fmpz")
132+
raise TypeError(f"cannot coerce {p=} to type fmpz")
133133

134134
if check_prime and not prime.is_prime():
135135
raise ValueError("characteristic is not prime")
136136

137137
# the degree must be strictly positive
138138
if d < 1:
139-
raise ValueError(f"the degree must be positive, got {d = }")
139+
raise ValueError(f"the degree must be positive, got {d=}")
140140

141141
fq_default_ctx_init_type(self.val, (<fmpz>prime).val, d, self.var, <fq_default_type>fq_type)
142142
self._initialized = True

src/flint/types/fq_default_poly.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cdef class fq_default_poly_ctx:
4747
# First coerce the list element as an fq_default type
4848
v = self.field.any_as_fq_default(val[i])
4949
if v is NotImplemented:
50-
raise TypeError(f"unsupported coefficient in list: {val[i] = }, {type(val[i]) = }")
50+
raise TypeError(f"unsupported coefficient in list: {val[i]=}, {type(val[i])=}")
5151

5252
# Set the coefficient of the polynomial
5353
fq_default_poly_set_coeff(
@@ -1324,7 +1324,7 @@ cdef class fq_default_poly(flint_poly):
13241324
"""
13251325
G, S, _ = self.xgcd(other)
13261326
if not G.is_one():
1327-
raise ValueError(f"polynomial has no inverse modulo {other = }")
1327+
raise ValueError(f"polynomial has no inverse modulo {other=}")
13281328
return S
13291329

13301330
# ====================================
@@ -1638,7 +1638,7 @@ cdef class fq_default_poly(flint_poly):
16381638
self.val, self.ctx.field.val
16391639
)
16401640
if n > n_max:
1641-
raise ValueError(f"Cannot deflate with {n = }, maximum allowed value is {n_max = }")
1641+
raise ValueError(f"Cannot deflate with {n=}, maximum allowed value is {n_max=}")
16421642

16431643
res = self.ctx.new_ctype_poly()
16441644
fq_default_poly_deflate(

src/flint/types/nmod_mat.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ cdef any_as_nmod_mat(obj, nmod_t mod):
6262
x = any_as_fmpz_mat(obj)
6363
if x is not NotImplemented:
6464
r = nmod_mat.__new__(nmod_mat)
65-
nmod_mat_init(r.val, fmpz_mat_nrows((<fmpz_mat>x).val),
66-
fmpz_mat_ncols((<fmpz_mat>x).val), mod.n)
65+
nmod_mat_init(r.val,
66+
fmpz_mat_nrows((<fmpz_mat>x).val),
67+
fmpz_mat_ncols((<fmpz_mat>x).val), mod.n)
6768
fmpz_mat_get_nmod_mat(r.val, (<fmpz_mat>x).val)
6869
return r
6970
return NotImplemented

src/flint/types/nmod_poly.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ cdef class nmod_poly(flint_poly):
155155
cdef mp_limb_t m
156156
n = self.length()
157157
m = self.modulus()
158-
L = [nmod(0,m) for i in range(n)] # XXX: speed up
158+
L = [nmod(0, m) for i in range(n)] # XXX: speed up
159159
for i from 0 <= i < n:
160160
(<nmod>(L[i])).val = nmod_poly_get_coeff_ui(self.val, i)
161161
return L
@@ -262,7 +262,7 @@ cdef class nmod_poly(flint_poly):
262262
45*x^4 + 23*x^3 + 159*x^2 + 151*x + 110
263263
"""
264264
if n <= 0:
265-
raise ValueError(f"{n = } must be positive")
265+
raise ValueError(f"{n=} must be positive")
266266

267267
if self.is_zero():
268268
raise ValueError("cannot invert the zero element")
@@ -315,11 +315,11 @@ cdef class nmod_poly(flint_poly):
315315
cdef nmod_poly res
316316
g = any_as_nmod_poly(other, self.val.mod)
317317
if g is NotImplemented:
318-
raise TypeError(f"cannot convert {other = } to nmod_poly")
318+
raise TypeError(f"cannot convert {other=} to nmod_poly")
319319

320320
h = any_as_nmod_poly(modulus, self.val.mod)
321321
if h is NotImplemented:
322-
raise TypeError(f"cannot convert {modulus = } to nmod_poly")
322+
raise TypeError(f"cannot convert {modulus=} to nmod_poly")
323323

324324
if modulus.is_zero():
325325
raise ZeroDivisionError("cannot reduce modulo zero")
@@ -549,7 +549,7 @@ cdef class nmod_poly(flint_poly):
549549
# For larger exponents we need to cast e to an fmpz first
550550
e_fmpz = any_as_fmpz(e)
551551
if e_fmpz is NotImplemented:
552-
raise TypeError(f"exponent cannot be cast to an fmpz type: {e = }")
552+
raise TypeError(f"exponent cannot be cast to an fmpz type: {e=}")
553553

554554
# To optimise powering, we precompute the inverse of the reverse of the modulus
555555
if mod_rev_inv is not None:

0 commit comments

Comments
 (0)