From 9fb3f92a9b79d9183c24b4d1021c966ffb0626ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 31 Aug 2024 12:59:02 +0200 Subject: [PATCH] activating more cython-lint checks --- doc/source/conf.py | 3 ++- pyproject.toml | 2 +- src/flint/types/acb.pyx | 4 ++-- src/flint/types/acb_mat.pyx | 4 ++-- src/flint/types/acb_series.pyx | 3 ++- src/flint/types/arb_mat.pyx | 4 ++-- src/flint/types/arb_series.pyx | 17 +++++++++-------- src/flint/types/dirichlet.pyx | 2 +- src/flint/types/fmpq_mat.pyx | 12 +++++++----- src/flint/types/fmpq_series.pyx | 2 +- src/flint/types/fmpz_mat.pyx | 4 ++-- src/flint/types/fmpz_mod.pyx | 7 ++----- src/flint/types/nmod_mat.pyx | 5 +++-- src/flint/types/nmod_poly.pyx | 2 +- 14 files changed, 37 insertions(+), 34 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 7a628d61..89345a87 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index a753b2ce..bfd3dee8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/src/flint/types/acb.pyx b/src/flint/types/acb.pyx index 0e60411f..15819309 100644 --- a/src/flint/types/acb.pyx +++ b/src/flint/types/acb.pyx @@ -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, ( y).val) - except: + except (TypeError, ValueError): import sys ictx.exn_type, ictx.exn_obj, ictx.exn_tb = sys.exc_info() acb_indeterminate(out) @@ -1346,7 +1346,7 @@ cdef class acb(flint_scalar): acb_hypgeom_gamma_upper((u).val, (s).val, (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. diff --git a/src/flint/types/acb_mat.pyx b/src/flint/types/acb_mat.pyx index be5dc44b..86609696 100644 --- a/src/flint/types/acb_mat.pyx +++ b/src/flint/types/acb_mat.pyx @@ -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), (x).val) else: raise TypeError("cannot create acb_mat from input of type %s" % type(val)) @@ -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) diff --git a/src/flint/types/acb_series.pyx b/src/flint/types/acb_series.pyx index 0e3130c6..c422b781 100644 --- a/src/flint/types/acb_series.pyx +++ b/src/flint/types/acb_series.pyx @@ -685,7 +685,8 @@ cdef class acb_series(flint_series): cap = getcap() cap = min(cap, (s).prec) u = acb_series.__new__(acb_series) - acb_hypgeom_airy_series(NULL, NULL, NULL, (u).val,(s).val, cap, getprec()) + acb_hypgeom_airy_series(NULL, NULL, NULL, (u).val, + (s).val, cap, getprec()) (u).prec = cap return u diff --git a/src/flint/types/arb_mat.pyx b/src/flint/types/arb_mat.pyx index 1a8c3fdb..ff106cca 100644 --- a/src/flint/types/arb_mat.pyx +++ b/src/flint/types/arb_mat.pyx @@ -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), (x).val) else: raise TypeError("cannot create arb_mat from input of type %s" % type(val)) @@ -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) diff --git a/src/flint/types/arb_series.pyx b/src/flint/types/arb_series.pyx index 4488bb57..ac61475a 100644 --- a/src/flint/types/arb_series.pyx +++ b/src/flint/types/arb_series.pyx @@ -668,7 +668,8 @@ cdef class arb_series(flint_series): cap = getcap() cap = min(cap, (s).prec) u = arb_series.__new__(arb_series) - arb_hypgeom_airy_series(NULL, NULL, NULL, (u).val,(s).val, cap, getprec()) + arb_hypgeom_airy_series(NULL, NULL, NULL, (u).val, + (s).val, cap, getprec()) (u).prec = cap return u @@ -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") @@ -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]) @@ -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 diff --git a/src/flint/types/dirichlet.pyx b/src/flint/types/dirichlet.pyx index 4ef2a4fd..ff8cab95 100644 --- a/src/flint/types/dirichlet.pyx +++ b/src/flint/types/dirichlet.pyx @@ -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): diff --git a/src/flint/types/fmpq_mat.pyx b/src/flint/types/fmpq_mat.pyx index 549a2fc4..5f56440f 100644 --- a/src/flint/types/fmpq_mat.pyx +++ b/src/flint/types/fmpq_mat.pyx @@ -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 * @@ -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((val).val), - fmpq_mat_ncols((val).val)) + fmpq_mat_init(self.val, + fmpq_mat_nrows((val).val), + fmpq_mat_ncols((val).val)) fmpq_mat_set(self.val, (val).val) elif typecheck(val, fmpz_mat): - fmpq_mat_init(self.val, fmpz_mat_nrows((val).val), - fmpz_mat_ncols((val).val)) + fmpq_mat_init(self.val, + fmpz_mat_nrows((val).val), + fmpz_mat_ncols((val).val)) fmpq_mat_set_fmpz_mat(self.val, (val).val) elif isinstance(val, (list, tuple)): m = len(val) diff --git a/src/flint/types/fmpq_series.pyx b/src/flint/types/fmpq_series.pyx index cb67e913..086e2c8b 100644 --- a/src/flint/types/fmpq_series.pyx +++ b/src/flint/types/fmpq_series.pyx @@ -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): diff --git a/src/flint/types/fmpz_mat.pyx b/src/flint/types/fmpz_mat.pyx index 82501a29..8c4a29ac 100644 --- a/src/flint/types/fmpz_mat.pyx +++ b/src/flint/types/fmpz_mat.pyx @@ -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) @@ -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: diff --git a/src/flint/types/fmpz_mod.pyx b/src/flint/types/fmpz_mod.pyx index 39c8316b..6d208f1a 100644 --- a/src/flint/types/fmpz_mod.pyx +++ b/src/flint/types/fmpz_mod.pyx @@ -400,11 +400,8 @@ cdef class fmpz_mod(flint_scalar): return NotImplemented res = fmpz_equal(self.val, (other).val) and \ - (self.ctx == (other).ctx) - if op == 2: - return res - else: - return not res + (self.ctx == (other).ctx) + return res if op == 2 else not res def __bool__(self): return not self.is_zero() diff --git a/src/flint/types/nmod_mat.pyx b/src/flint/types/nmod_mat.pyx index c528fdb2..fc5b36ba 100644 --- a/src/flint/types/nmod_mat.pyx +++ b/src/flint/types/nmod_mat.pyx @@ -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((x).val), - fmpz_mat_ncols((x).val), mod.n) + nmod_mat_init(r.val, + fmpz_mat_nrows((x).val), + fmpz_mat_ncols((x).val), mod.n) fmpz_mat_get_nmod_mat(r.val, (x).val) return r return NotImplemented diff --git a/src/flint/types/nmod_poly.pyx b/src/flint/types/nmod_poly.pyx index 51518266..020448b2 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -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: ((L[i])).val = nmod_poly_get_coeff_ui(self.val, i) return L