Skip to content

More cython lint checks #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys
import os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ build-backend = "mesonpy"

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

[tool.spin]
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/acb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ cdef int acb_calc_func_callback(acb_ptr out, const acb_t inp, void * param, long
if not typecheck(y, acb):
raise TypeError("integrand must return an acb")
acb_set(out, (<acb> y).val)
except:
except (TypeError, ValueError):
import sys
ictx.exn_type, ictx.exn_obj, ictx.exn_tb = sys.exc_info()
acb_indeterminate(out)
Expand Down Expand Up @@ -1346,7 +1346,7 @@ cdef class acb(flint_scalar):
acb_hypgeom_gamma_upper((<acb>u).val, (<acb>s).val, (<acb>self).val, regularized, getprec())
return u

def gamma_lower(self,s, int regularized=0):
def gamma_lower(self, s, int regularized=0):
r"""
Lower incomplete gamma function `\gamma(s,z)`. The argument *z*
is given by *self* and the order *s* is passed as an extra parameter.
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/acb_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ cdef class acb_mat(flint_mat):
acb_mat_init(self.val, m, n)
for i from 0 <= i < m:
for j from 0 <= j < n:
x = acb(val[i,j])
x = acb(val[i, j])
acb_set(acb_mat_entry(self.val, i, j), (<acb>x).val)
else:
raise TypeError("cannot create acb_mat from input of type %s" % type(val))
Expand All @@ -137,7 +137,7 @@ cdef class acb_mat(flint_mat):
if isinstance(entries, (int, float, complex, fmpz, fmpq, arb, acb)):
c = entries
entries = [0] * (m * n)
for i in range(min(m,n)):
for i in range(min(m, n)):
entries[i*n + i] = c
else:
entries = list(entries)
Expand Down
3 changes: 2 additions & 1 deletion src/flint/types/acb_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ cdef class acb_series(flint_series):
cap = getcap()
cap = min(cap, (<acb_series>s).prec)
u = acb_series.__new__(acb_series)
acb_hypgeom_airy_series(NULL, NULL, NULL, (<acb_series>u).val,(<acb_series>s).val, cap, getprec())
acb_hypgeom_airy_series(NULL, NULL, NULL, (<acb_series>u).val,
(<acb_series>s).val, cap, getprec())
(<acb_series>u).prec = cap
return u

Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/arb_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ cdef class arb_mat(flint_mat):
arb_mat_init(self.val, m, n)
for i from 0 <= i < m:
for j from 0 <= j < n:
x = arb(val[i,j])
x = arb(val[i, j])
arb_set(arb_mat_entry(self.val, i, j), (<arb>x).val)
else:
raise TypeError("cannot create arb_mat from input of type %s" % type(val))
Expand All @@ -135,7 +135,7 @@ cdef class arb_mat(flint_mat):
if isinstance(entries, (int, float, fmpz, fmpq, arb)):
c = entries
entries = [0] * (m * n)
for i in range(min(m,n)):
for i in range(min(m, n)):
entries[i*n + i] = c
else:
entries = list(entries)
Expand Down
17 changes: 9 additions & 8 deletions src/flint/types/arb_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ cdef class arb_series(flint_series):
cap = getcap()
cap = min(cap, (<arb_series>s).prec)
u = arb_series.__new__(arb_series)
arb_hypgeom_airy_series(NULL, NULL, NULL, (<arb_series>u).val,(<arb_series>s).val, cap, getprec())
arb_hypgeom_airy_series(NULL, NULL, NULL, (<arb_series>u).val,
(<arb_series>s).val, cap, getprec())
(<arb_series>u).prec = cap
return u

Expand Down Expand Up @@ -813,7 +814,7 @@ cdef class arb_series(flint_series):
try:
roots = []
ctx.cap = 1
queue = [(arb(a),arb(b))]
queue = [(arb(a), arb(b))]
qvals = [(xsgn(f(arb_series(a))[0]), xsgn(f(arb_series(b))[0]))]
if 0 in qvals[0]:
raise ValueError("unknown sign at an endpoint; try a slightly larger interval")
Expand All @@ -833,8 +834,8 @@ cdef class arb_series(flint_series):
#fa = xsgn(f(arb_series(a))[0])
#fb = xsgn(f(arb_series(b))[0])
ctx.cap = 2
if fa * fb < 0 and f(arb_series([arb(m, r),1]))[1] != 0:
roots.append((a,b))
if fa * fb < 0 and f(arb_series([arb(m, r), 1]))[1] != 0:
roots.append((a, b))
continue
ctx.cap = 1
fm = xsgn(f(arb_series(m))[0])
Expand All @@ -843,10 +844,10 @@ cdef class arb_series(flint_series):
fm = xsgn(f(arb_series(m))[0])
if fm == 0:
raise ValueError("unknown sign at a bisection point")
queue.append((m,b))
qvals.append((fm,fb))
queue.append((a,m))
qvals.append((fa,fm))
queue.append((m, b))
qvals.append((fm, fb))
queue.append((a, m))
qvals.append((fa, fm))
finally:
ctx.cap = orig_cap
return roots
2 changes: 1 addition & 1 deletion src/flint/types/dirichlet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ cdef class dirichlet_char(object):
_dirichlet_group_cache[q] = G
self.G = G
dirichlet_char_init(self.val, self.G.val)
assert 1 <= l <= max(q,2)-1 and n_gcd(q, l) == 1
assert 1 <= l <= max(q, 2)-1 and n_gcd(q, l) == 1
dirichlet_char_log(self.val, self.G.val, l)

def group(self):
Expand Down
12 changes: 7 additions & 5 deletions src/flint/types/fmpq_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from flint.types.fmpq cimport any_as_fmpq
from flint.types.fmpz cimport any_as_fmpz

from flint.flintlib.fmpz_mat cimport fmpz_mat_nrows, fmpz_mat_ncols
from flint.flintlib.fmpq cimport fmpq_set,fmpq_numref, fmpq_denref
from flint.flintlib.fmpq cimport fmpq_set, fmpq_numref, fmpq_denref
from flint.flintlib.fmpq_poly cimport fmpq_poly_init
from flint.flintlib.fmpq_mat cimport *

Expand Down Expand Up @@ -48,12 +48,14 @@ cdef class fmpq_mat(flint_mat):
if len(args) == 1:
val = args[0]
if typecheck(val, fmpq_mat):
fmpq_mat_init(self.val, fmpq_mat_nrows((<fmpq_mat>val).val),
fmpq_mat_ncols((<fmpq_mat>val).val))
fmpq_mat_init(self.val,
fmpq_mat_nrows((<fmpq_mat>val).val),
fmpq_mat_ncols((<fmpq_mat>val).val))
fmpq_mat_set(self.val, (<fmpq_mat>val).val)
elif typecheck(val, fmpz_mat):
fmpq_mat_init(self.val, fmpz_mat_nrows((<fmpz_mat>val).val),
fmpz_mat_ncols((<fmpz_mat>val).val))
fmpq_mat_init(self.val,
fmpz_mat_nrows((<fmpz_mat>val).val),
fmpz_mat_ncols((<fmpz_mat>val).val))
fmpq_mat_set_fmpz_mat(self.val, (<fmpz_mat>val).val)
elif isinstance(val, (list, tuple)):
m = len(val)
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/fmpq_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from flint.types.acb_poly cimport acb_poly
from flint.types.acb_series cimport acb_series
from flint.types.fmpz cimport any_as_fmpz

from flint.flintlib.fmpz cimport fmpz_is_zero,fmpz_set,fmpz_equal
from flint.flintlib.fmpz cimport fmpz_is_zero, fmpz_set, fmpz_equal
from flint.flintlib.fmpq_poly cimport *

cdef fmpq_series_coerce_operands(x, y):
Expand Down
4 changes: 2 additions & 2 deletions src/flint/types/fmpz_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cdef class fmpz_mat(flint_mat):

"""

# cdef fmpz_mat_t val
# cdef fmpz_mat_t val

def __cinit__(self):
fmpz_mat_init(self.val, 0, 0)
Expand Down Expand Up @@ -651,7 +651,7 @@ cdef class fmpz_mat(flint_mat):
if transform:
v = fmpz_mat(self.nrows(), self.nrows())
for 0 <= i < self.nrows():
v[i,i] = 1
v[i, i] = 1
fmpz_lll(u.val, v.val, ctx)
return u, v
else:
Expand Down
7 changes: 2 additions & 5 deletions src/flint/types/fmpz_mod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,8 @@ cdef class fmpz_mod(flint_scalar):
return NotImplemented

res = fmpz_equal(self.val, (<fmpz_mod>other).val) and \
(self.ctx == (<fmpz_mod>other).ctx)
if op == 2:
return res
else:
return not res
(self.ctx == (<fmpz_mod>other).ctx)
return res if op == 2 else not res

def __bool__(self):
return not self.is_zero()
Expand Down
5 changes: 3 additions & 2 deletions src/flint/types/nmod_mat.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ cdef any_as_nmod_mat(obj, nmod_t mod):
x = any_as_fmpz_mat(obj)
if x is not NotImplemented:
r = nmod_mat.__new__(nmod_mat)
nmod_mat_init(r.val, fmpz_mat_nrows((<fmpz_mat>x).val),
fmpz_mat_ncols((<fmpz_mat>x).val), mod.n)
nmod_mat_init(r.val,
fmpz_mat_nrows((<fmpz_mat>x).val),
fmpz_mat_ncols((<fmpz_mat>x).val), mod.n)
fmpz_mat_get_nmod_mat(r.val, (<fmpz_mat>x).val)
return r
return NotImplemented
Expand Down
2 changes: 1 addition & 1 deletion src/flint/types/nmod_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ cdef class nmod_poly(flint_poly):
cdef mp_limb_t m
n = self.length()
m = self.modulus()
L = [nmod(0,m) for i in range(n)] # XXX: speed up
L = [nmod(0, m) for i in range(n)] # XXX: speed up
for i from 0 <= i < n:
(<nmod>(L[i])).val = nmod_poly_get_coeff_ui(self.val, i)
return L
Expand Down
Loading