From 45ce25d5c07031da158969c1343660253870cdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 30 Aug 2024 20:16:57 +0200 Subject: [PATCH 1/5] first sketch of cython-lint workflow --- .github/workflows/lint.yml | 26 ++++++++++++++++++++++++++ pyproject.toml | 5 +++++ 2 files changed, 31 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..1347b100 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,26 @@ +name: Linting + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install uv + uv pip install cython-lint --upgrade --system + + - name: cython-lint + run: | + cython-lint --ignore=E114,E117,E127,E128,E129,E202,E221,E222,E231,E261,E262,E265,E302,E303,E306,E501,E701,E703,E711,E722,E731,E741,E743,W291,W293,W391,W605 src/ diff --git a/pyproject.toml b/pyproject.toml index e10b47aa..6885d4cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,11 @@ content-type = "text/markdown" requires = ["meson-python>=0.13", "cython>=3.0,<3.1"] build-backend = "mesonpy" +[tool.cython-lint] +max-line-length = 120 +ignore = ['E225', 'E231', 'E501', 'E741'] +exclude = 'src/flint/flintlib/.*' + [tool.spin] package = "flint" From 97e9f79e667a78452d19d5a354f553c6de9e485b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 30 Aug 2024 21:05:00 +0200 Subject: [PATCH 2/5] remove unused variables --- src/flint/types/acb.pyx | 20 ++++++++++---------- src/flint/types/acb_mat.pyx | 2 -- src/flint/types/acb_poly.pyx | 2 +- src/flint/types/acb_series.pyx | 2 +- src/flint/types/arb.pyx | 4 ++-- src/flint/types/arb_mat.pyx | 3 --- src/flint/types/arf.pyx | 1 - src/flint/types/dirichlet.pyx | 1 - src/flint/types/fmpq.pyx | 1 - src/flint/types/fmpq_mat.pyx | 3 --- src/flint/types/fmpq_mpoly.pyx | 2 +- src/flint/types/fmpq_poly.pyx | 4 ---- src/flint/types/fmpz.pyx | 3 --- src/flint/types/fmpz_mat.pyx | 1 - src/flint/types/fmpz_mod.pyx | 2 -- src/flint/types/fmpz_mod_mat.pyx | 11 ----------- src/flint/types/fmpz_mod_mpoly.pyx | 2 +- src/flint/types/fmpz_mod_poly.pyx | 12 ++++++------ src/flint/types/fmpz_mpoly.pyx | 2 +- src/flint/types/fq_default_poly.pyx | 14 +++++--------- src/flint/types/nmod.pyx | 3 +-- src/flint/types/nmod_mat.pyx | 2 -- src/flint/types/nmod_poly.pyx | 4 +--- 23 files changed, 30 insertions(+), 71 deletions(-) diff --git a/src/flint/types/acb.pyx b/src/flint/types/acb.pyx index f29e3520..e188d700 100644 --- a/src/flint/types/acb.pyx +++ b/src/flint/types/acb.pyx @@ -87,15 +87,15 @@ cdef any_as_acb_or_notimplemented(x): return NotImplemented return t -""" -cdef any_as_arb_or_acb(x): - if typecheck(x, arb) or typecheck(x, acb): - return x - try: - return arb(x) - except (TypeError, ValueError): - return acb(x) -""" + +# cdef any_as_arb_or_acb(x): +# if typecheck(x, arb) or typecheck(x, acb): +# return x +# try: +# return arb(x) +# except (TypeError, ValueError): +# return acb(x) + # Copied with modifications from sage/rings/complex_arb.pyx @@ -2387,7 +2387,7 @@ cdef class acb(flint_scalar): of terms to add in the hypergeometric series. This is just a tuning parameter: a rigorous error bound is computed regardless of *n*. """ - cdef long i, p, q, prec + cdef long i, p, q cdef acb_ptr aa, bb a = [any_as_acb(t) for t in a] b = [any_as_acb(t) for t in b] diff --git a/src/flint/types/acb_mat.pyx b/src/flint/types/acb_mat.pyx index 2d4cd41e..be5dc44b 100644 --- a/src/flint/types/acb_mat.pyx +++ b/src/flint/types/acb_mat.pyx @@ -331,7 +331,6 @@ cdef class acb_mat(flint_mat): return u def __truediv__(s, t): - cdef acb_mat u if typecheck(s, acb_mat): s, t = acb_mat_coerce_scalar(s, t) if s is NotImplemented: @@ -597,7 +596,6 @@ cdef class acb_mat(flint_mat): return u def __richcmp__(s, t, int op): - cdef int stype, ttype cdef bint res if not (op == 2 or op == 3): raise ValueError("comparing matrices") diff --git a/src/flint/types/acb_poly.pyx b/src/flint/types/acb_poly.pyx index d9f9925e..3e73bebe 100644 --- a/src/flint/types/acb_poly.pyx +++ b/src/flint/types/acb_poly.pyx @@ -363,7 +363,7 @@ cdef class acb_poly(flint_poly): ValueError: roots() failed to converge: insufficient precision, or squareful input """ - cdef long prec, initial_prec, target_prec, isolated, maxiter, deg, i + cdef long prec, initial_prec, isolated, maxiter, deg, i cdef acb_ptr roots cdef acb_poly_t tmp deg = s.degree() diff --git a/src/flint/types/acb_series.pyx b/src/flint/types/acb_series.pyx index a7b7137d..b1b0d391 100644 --- a/src/flint/types/acb_series.pyx +++ b/src/flint/types/acb_series.pyx @@ -629,7 +629,7 @@ cdef class acb_series(flint_series): of terms to add in the hypergeometric series. This is just a tuning parameter: a rigorous error bound is computed regardless of *n*. """ - cdef long i, p, q, prec, cap + cdef long i, p, q, cap cdef acb_poly_struct * aa cdef acb_poly_struct * bb a = [acb_series(t) for t in a] diff --git a/src/flint/types/arb.pyx b/src/flint/types/arb.pyx index e139819b..dd6a55d1 100644 --- a/src/flint/types/arb.pyx +++ b/src/flint/types/arb.pyx @@ -43,7 +43,7 @@ cdef arb_from_str(str s): raise ValueError("invalid string for arb()") cdef arb_set_mpmath_mpf(arb_t x, obj): - sgn, man, exp, bc = obj + sgn, man, exp, _ = obj if not man: if not exp: @@ -2171,7 +2171,7 @@ cdef class arb(flint_scalar): >>> showgood(lambda: arb(5).hypgeom([1,2,3],[5,4.5,6],regularized=True), dps=25) 3.886189282817193519132054e-5 """ - cdef long i, p, q, prec + cdef long i, p, q cdef arb_ptr aa, bb a = [any_as_arb(t) for t in a] b = [any_as_arb(t) for t in b] diff --git a/src/flint/types/arb_mat.pyx b/src/flint/types/arb_mat.pyx index d3bd310a..1a8c3fdb 100644 --- a/src/flint/types/arb_mat.pyx +++ b/src/flint/types/arb_mat.pyx @@ -300,7 +300,6 @@ cdef class arb_mat(flint_mat): return u def __rmul__(s, t): - cdef arb_mat u c, d = arb_mat_coerce_scalar(s, t) if c is not NotImplemented: return c._scalar_mul_(d) @@ -317,7 +316,6 @@ cdef class arb_mat(flint_mat): return u def __truediv__(s, t): - cdef arb_mat u s, t = arb_mat_coerce_scalar(s, t) if s is NotImplemented: return s @@ -669,7 +667,6 @@ cdef class arb_mat(flint_mat): return u def __richcmp__(s, t, int op): - cdef int stype, ttype cdef bint res if not (op == 2 or op == 3): raise ValueError("comparing matrices") diff --git a/src/flint/types/arf.pyx b/src/flint/types/arf.pyx index 5c8fcb23..5f1e930a 100644 --- a/src/flint/types/arf.pyx +++ b/src/flint/types/arf.pyx @@ -89,7 +89,6 @@ cdef class arf: return man, exp def _repr_str(self): - cdef fmpz man, exp if arf_is_zero(self.val): return "0.0" elif arf_is_finite(self.val): diff --git a/src/flint/types/dirichlet.pyx b/src/flint/types/dirichlet.pyx index a34c0f24..4ef2a4fd 100644 --- a/src/flint/types/dirichlet.pyx +++ b/src/flint/types/dirichlet.pyx @@ -163,7 +163,6 @@ cdef class dirichlet_char(object): cdef fmpz m cdef ulong v m = fmpz(n) % self.G.q - expo = self.G.exponent() v = dirichlet_chi(self.G.val, self.val, fmpz_get_ui(m.val)) if v == DIRICHLET_CHI_NULL: return None diff --git a/src/flint/types/fmpq.pyx b/src/flint/types/fmpq.pyx index ab5aa985..f9748619 100644 --- a/src/flint/types/fmpq.pyx +++ b/src/flint/types/fmpq.pyx @@ -470,7 +470,6 @@ cdef class fmpq(flint_scalar): cdef int ntype = FMPZ_UNKNOWN cdef fmpq v cdef int success - cdef long e assert z is None diff --git a/src/flint/types/fmpq_mat.pyx b/src/flint/types/fmpq_mat.pyx index 59959789..f9b8a1c3 100644 --- a/src/flint/types/fmpq_mat.pyx +++ b/src/flint/types/fmpq_mat.pyx @@ -233,7 +233,6 @@ cdef class fmpq_mat(flint_mat): return u def __mul__(s, t): - cdef fmpz_mat u if typecheck(t, fmpq_mat): return (s).__mul_fmpq_mat(t) elif typecheck(t, fmpz_mat): @@ -248,7 +247,6 @@ cdef class fmpq_mat(flint_mat): return NotImplemented def __rmul__(s, t): - cdef fmpz_mat u if typecheck(t, fmpz_mat): return (s).__mul_r_fmpz_mat(t) else: @@ -433,7 +431,6 @@ cdef class fmpq_mat(flint_mat): 60 """ cdef fmpz_mat num - cdef fmpz_den num = fmpz_mat(self.nrows(), self.ncols()) den = fmpz() fmpq_mat_get_fmpz_mat_matwise(num.val, den.val, self.val) diff --git a/src/flint/types/fmpq_mpoly.pyx b/src/flint/types/fmpq_mpoly.pyx index dfecb0f9..d13d1c0d 100644 --- a/src/flint/types/fmpq_mpoly.pyx +++ b/src/flint/types/fmpq_mpoly.pyx @@ -609,7 +609,7 @@ cdef class fmpq_mpoly(flint_mpoly): fmpq_mpoly res fmpq_mpoly_ctx res_ctx fmpq_mpoly_vec C - slong i, nvars = self.ctx.nvars(), nargs = len(args) + slong nvars = self.ctx.nvars(), nargs = len(args) if nargs < nvars: raise ValueError("not enough arguments provided") diff --git a/src/flint/types/fmpq_poly.pyx b/src/flint/types/fmpq_poly.pyx index 0a00fbe5..f9e6df48 100644 --- a/src/flint/types/fmpq_poly.pyx +++ b/src/flint/types/fmpq_poly.pyx @@ -287,14 +287,12 @@ cdef class fmpq_poly(flint_poly): return r def __floordiv__(s, t): - cdef fmpq_poly r t = any_as_fmpq_poly(t) if t is NotImplemented: return t return s._floordiv_(t) def __rfloordiv__(s, t): - cdef fmpq_poly r t = any_as_fmpq_poly(t) if t is NotImplemented: return t @@ -309,14 +307,12 @@ cdef class fmpq_poly(flint_poly): return r def __mod__(s, t): - cdef fmpq_poly r t = any_as_fmpq_poly(t) if t is NotImplemented: return t return s._mod_(t) def __rmod__(s, t): - cdef fmpq_poly r t = any_as_fmpq_poly(t) if t is NotImplemented: return t diff --git a/src/flint/types/fmpz.pyx b/src/flint/types/fmpz.pyx index c6c1d30d..537e064a 100644 --- a/src/flint/types/fmpz.pyx +++ b/src/flint/types/fmpz.pyx @@ -69,7 +69,6 @@ cdef class fmpz(flint_scalar): fmpz_clear(self.val) def __init__(self, *args): - cdef long x if not args: return elif len(args) != 1: @@ -123,7 +122,6 @@ cdef class fmpz(flint_scalar): def __richcmp__(s, t, int op): cdef bint res = 0 - cdef long tl cdef fmpz_struct tval[1] cdef fmpz_struct * sval cdef int ttype @@ -1019,7 +1017,6 @@ cdef class fmpz(flint_scalar): ttype = fmpz_set_any_ref(tval, other) if ttype == FMPZ_UNKNOWN: raise TypeError("input must be an integer") - u = fmpz.__new__(fmpz) v = fmpz_jacobi(self.val, tval) if ttype == FMPZ_TMP: fmpz_clear(tval) diff --git a/src/flint/types/fmpz_mat.pyx b/src/flint/types/fmpz_mat.pyx index 69b05a87..d8d68f27 100644 --- a/src/flint/types/fmpz_mat.pyx +++ b/src/flint/types/fmpz_mat.pyx @@ -252,7 +252,6 @@ cdef class fmpz_mat(flint_mat): cdef fmpz_mat u cdef fmpz_mat_struct *sval cdef fmpz_mat_struct *tval - cdef int ttype if typecheck(t, fmpz_mat): sval = &(s).val[0] tval = &(t).val[0] diff --git a/src/flint/types/fmpz_mod.pyx b/src/flint/types/fmpz_mod.pyx index 475a5ef0..7d134754 100644 --- a/src/flint/types/fmpz_mod.pyx +++ b/src/flint/types/fmpz_mod.pyx @@ -341,8 +341,6 @@ cdef class fmpz_mod(flint_scalar): >>> g.discrete_log(a) 123 """ - cdef bint is_prime - # Ensure that the modulus is prime if not self.ctx.is_prime(): raise NotImplementedError("algorithm assumes modulus is prime") diff --git a/src/flint/types/fmpz_mod_mat.pyx b/src/flint/types/fmpz_mod_mat.pyx index 923fa6fd..9722cecf 100644 --- a/src/flint/types/fmpz_mod_mat.pyx +++ b/src/flint/types/fmpz_mod_mat.pyx @@ -408,47 +408,37 @@ cdef class fmpz_mod_mat(flint_mat): def __add__(self, other): """``M + N``: Add two matrices.""" - cdef fmpz_mod_mat o other = self._as_fmpz_mod_mat(other) if other is NotImplemented: return NotImplemented - o = other return self._add(other) def __radd__(self, other): """``N + M``: Add two matrices.""" - cdef fmpz_mod_mat o other = self._as_fmpz_mod_mat(other) if other is NotImplemented: return NotImplemented - o = other return other._add(self) def __sub__(self, other): """``M - N``: Subtract two matrices.""" - cdef fmpz_mod_mat o other = self._as_fmpz_mod_mat(other) if other is NotImplemented: return NotImplemented - o = other return self._sub(other) def __rsub__(self, other): """``N - M``: Subtract two matrices.""" - cdef fmpz_mod_mat o other = self._as_fmpz_mod_mat(other) if other is NotImplemented: return NotImplemented - o = other return other._sub(self) def __mul__(self, other): """``M * N``: Multiply two matrices.""" - cdef fmpz_mod_mat o cdef fmpz_mod e other_mat = self._as_fmpz_mod_mat(other, same_shape=False) if other_mat is not NotImplemented: - o = other_mat return self._matmul(other_mat) other_scalar = self.ctx.any_as_fmpz_mod(other) if other_scalar is not NotImplemented: @@ -461,7 +451,6 @@ cdef class fmpz_mod_mat(flint_mat): cdef fmpz_mod e other_mat = self._as_fmpz_mod_mat(other) if other_mat is not NotImplemented: - o = other_mat return other_mat._matmul(self) other_scalar = self.ctx.any_as_fmpz_mod(other) if other_scalar is not NotImplemented: diff --git a/src/flint/types/fmpz_mod_mpoly.pyx b/src/flint/types/fmpz_mod_mpoly.pyx index 7018a2a0..1326624c 100644 --- a/src/flint/types/fmpz_mod_mpoly.pyx +++ b/src/flint/types/fmpz_mod_mpoly.pyx @@ -685,7 +685,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly): fmpz_mod_mpoly res fmpz_mod_mpoly_ctx res_ctx fmpz_mod_mpoly_vec C - slong i, nvars = self.ctx.nvars(), nargs = len(args) + slong nvars = self.ctx.nvars(), nargs = len(args) if nargs != nvars: raise ValueError("number of generators does not match number of arguments") diff --git a/src/flint/types/fmpz_mod_poly.pyx b/src/flint/types/fmpz_mod_poly.pyx index ec216a06..0e1b579b 100644 --- a/src/flint/types/fmpz_mod_poly.pyx +++ b/src/flint/types/fmpz_mod_poly.pyx @@ -180,7 +180,7 @@ cdef class fmpz_mod_poly_ctx: val_fmpz = any_as_fmpz(val[i]) if val_fmpz is NotImplemented: fmpz_clear(x) - raise TypeError(f"unsupported coefficient in list") + raise TypeError("unsupported coefficient in list") fmpz_mod_poly_set_coeff_fmpz( poly, i, ((val_fmpz)).val, self.mod.val ) @@ -438,7 +438,7 @@ cdef class fmpz_mod_poly(flint_poly): return NotImplemented if other == 0: - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") elif not other.is_unit(): raise DomainError(f"Cannot divide by {other} modulo {self.ctx.modulus()}") @@ -485,7 +485,7 @@ cdef class fmpz_mod_poly(flint_poly): raise TypeError(f"Cannot convert {right} to `fmpz_mod_poly` type.") if right == 0: - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") res = self.ctx.new_ctype_poly() check = fmpz_mod_poly_divides( @@ -522,7 +522,7 @@ cdef class fmpz_mod_poly(flint_poly): lc = right.leading_coefficient() if lc.is_zero(): - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") elif not lc.is_unit(): raise DomainError(f"The leading term of {right} must be a unit modulo N") @@ -642,7 +642,7 @@ cdef class fmpz_mod_poly(flint_poly): return NotImplemented if right == 0: - raise ZeroDivisionError(f"Cannot reduce modulo zero") + raise ZeroDivisionError("Cannot reduce modulo zero") res = (left).ctx.new_ctype_poly() fmpz_init(f) @@ -1059,7 +1059,7 @@ cdef class fmpz_mod_poly(flint_poly): ) if not fmpz_is_one(f): fmpz_clear(f) - raise ValueError(f"Leading coefficient is not invertible") + raise ValueError("Leading coefficient is not invertible") return res def is_irreducible(self): diff --git a/src/flint/types/fmpz_mpoly.pyx b/src/flint/types/fmpz_mpoly.pyx index 43420ad2..b5390cbc 100644 --- a/src/flint/types/fmpz_mpoly.pyx +++ b/src/flint/types/fmpz_mpoly.pyx @@ -591,7 +591,7 @@ cdef class fmpz_mpoly(flint_mpoly): fmpz_mpoly res fmpz_mpoly_ctx res_ctx fmpz_mpoly_vec C - slong i, nvars = self.ctx.nvars(), nargs = len(args) + slong nvars = self.ctx.nvars(), nargs = len(args) if nargs < nvars: raise ValueError("not enough arguments provided") diff --git a/src/flint/types/fq_default_poly.pyx b/src/flint/types/fq_default_poly.pyx index a623f259..982607e8 100644 --- a/src/flint/types/fq_default_poly.pyx +++ b/src/flint/types/fq_default_poly.pyx @@ -36,7 +36,6 @@ cdef class fq_default_poly_ctx: cdef set_list_as_fq_default_poly(self, fq_default_poly_t poly, val): cdef long i, n - cdef fmpz_t x # Get size of list and create a polynomial of length n n = PyList_GET_SIZE(val) @@ -705,7 +704,6 @@ cdef class fq_default_poly(flint_poly): >>> f.divmod(g) (21, 106*x^5 + 156*x^4 + 131*x^3 + 43*x^2 + 86*x + 16) """ - cdef fmpz_t f cdef fq_default_poly Q, R other = self.ctx.any_as_fq_default_poly(other) @@ -753,7 +751,7 @@ cdef class fq_default_poly(flint_poly): raise TypeError(f"Cannot convert {other} to `fq_default_poly` type.") if other.is_zero(): - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") res = self.ctx.new_ctype_poly() check = fq_default_poly_divides( @@ -775,7 +773,7 @@ cdef class fq_default_poly(flint_poly): scalar = self.ctx.field.any_as_fq_default(other) if scalar is not NotImplemented: if scalar.is_zero(): - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") fq_default_poly_scalar_div_fq_default( res.val, self.val, (scalar).val, self.ctx.field.val ) @@ -786,7 +784,7 @@ cdef class fq_default_poly(flint_poly): def __rtruediv__(self, other): if self.is_zero(): - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") other = self.ctx.any_as_fq_default_poly(other) if other is NotImplemented: return other @@ -801,7 +799,7 @@ cdef class fq_default_poly(flint_poly): scalar = self.ctx.field.any_as_fq_default(other) if scalar is not NotImplemented: if scalar.is_zero(): - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") fq_default_poly_scalar_div_fq_default( res.val, self.val, (scalar).val, self.ctx.field.val ) @@ -814,7 +812,7 @@ cdef class fq_default_poly(flint_poly): # Do not divide by zero if other.is_zero(): - raise ZeroDivisionError(f"Cannot divide by zero") + raise ZeroDivisionError("Cannot divide by zero") # floor division uses divmod but ignores the rem term cdef fq_default_poly rem @@ -1240,7 +1238,6 @@ cdef class fq_default_poly(flint_poly): >>> f.mul_low(h, 4).is_one() True """ - cdef fmpz_t f cdef fq_default_poly res if self.constant_coefficient().is_zero(): @@ -1298,7 +1295,6 @@ cdef class fq_default_poly(flint_poly): """ cdef fq_default_poly G, S, T - cdef fmpz_t f other = self.ctx.any_as_fq_default_poly(other) if other is NotImplemented: diff --git a/src/flint/types/nmod.pyx b/src/flint/types/nmod.pyx index 20cd03a9..93093ca9 100644 --- a/src/flint/types/nmod.pyx +++ b/src/flint/types/nmod.pyx @@ -69,7 +69,6 @@ cdef class nmod(flint_scalar): return self.mod.n def __richcmp__(s, t, int op): - cdef mp_limb_t v cdef bint res if op != 2 and op != 3: raise TypeError("nmods cannot be ordered") @@ -166,7 +165,7 @@ cdef class nmod(flint_scalar): @staticmethod def _div_(s, t): cdef nmod r - cdef mp_limb_t sval, tval, x + cdef mp_limb_t sval, tval cdef nmod_t mod cdef ulong tinvval diff --git a/src/flint/types/nmod_mat.pyx b/src/flint/types/nmod_mat.pyx index 8c99e2ef..c528fdb2 100644 --- a/src/flint/types/nmod_mat.pyx +++ b/src/flint/types/nmod_mat.pyx @@ -57,7 +57,6 @@ ctx = thectx cdef any_as_nmod_mat(obj, nmod_t mod): cdef nmod_mat r - cdef mp_limb_t v if typecheck(obj, nmod_mat): return obj x = any_as_fmpz_mat(obj) @@ -140,7 +139,6 @@ cdef class nmod_mat(flint_mat): return not nmod_mat_is_zero(self.val) def __richcmp__(s, t, int op): - cdef mp_limb_t v cdef bint res if op != 2 and op != 3: raise TypeError("matrices cannot be ordered") diff --git a/src/flint/types/nmod_poly.pyx b/src/flint/types/nmod_poly.pyx index ea4239d6..853521ff 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -43,7 +43,6 @@ cdef nmod_poly_set_list(nmod_poly_t poly, list val): n = PyList_GET_SIZE(val) nmod_poly_fit_length(poly, n) for i from 0 <= i < n: - c = val[i] if any_as_nmod(&v, val[i], mod): nmod_poly_set_coeff_ui(poly, i, v) else: @@ -115,7 +114,6 @@ cdef class nmod_poly(flint_poly): return nmod_poly_modulus(self.val) def __richcmp__(s, t, int op): - cdef mp_limb_t v cdef bint res if op != 2 and op != 3: raise TypeError("nmod_polys cannot be ordered") @@ -268,7 +266,7 @@ cdef class nmod_poly(flint_poly): raise ValueError(f"{n = } must be positive") if self.is_zero(): - raise ValueError(f"cannot invert the zero element") + raise ValueError("cannot invert the zero element") cdef nmod_poly res res = nmod_poly.__new__(nmod_poly) From ab23417d8a35046fa59bf8f518a9b178e850269d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 30 Aug 2024 21:11:37 +0200 Subject: [PATCH 3/5] remove unused imports --- src/flint/pyflint.pyx | 3 +-- src/flint/types/acb_series.pyx | 1 - src/flint/types/arb.pyx | 2 +- src/flint/types/arb_poly.pyx | 1 - src/flint/types/fmpq.pyx | 2 +- src/flint/types/fmpq_mat.pyx | 4 +--- src/flint/types/fmpq_mpoly.pyx | 2 -- src/flint/types/fmpz_mat.pyx | 1 - src/flint/types/fmpz_mod.pyx | 1 - src/flint/types/fmpz_mod_mat.pyx | 3 --- src/flint/types/fmpz_mod_mpoly.pyx | 1 - src/flint/types/fmpz_mpoly.pyx | 1 - src/flint/types/fmpz_poly.pyx | 1 - src/flint/types/fmpz_vec.pyx | 4 ---- src/flint/types/nmod.pyx | 2 +- src/flint/types/nmod_mpoly.pyx | 3 +-- src/flint/types/nmod_poly.pyx | 1 - 17 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/flint/pyflint.pyx b/src/flint/pyflint.pyx index fcb6afbe..3765d437 100644 --- a/src/flint/pyflint.pyx +++ b/src/flint/pyflint.pyx @@ -2,9 +2,8 @@ Python wrapper for FLINT and Arb. """ -cimport flint +# cimport flint cimport libc.stdlib -cimport cython from flint.flint_base.flint_context cimport thectx diff --git a/src/flint/types/acb_series.pyx b/src/flint/types/acb_series.pyx index b1b0d391..03e7ca7e 100644 --- a/src/flint/types/acb_series.pyx +++ b/src/flint/types/acb_series.pyx @@ -8,7 +8,6 @@ from flint.types.acb cimport acb from flint.types.fmpz_poly cimport fmpz_poly from flint.types.fmpq_poly cimport fmpq_poly from flint.types.arb_poly cimport arb_poly -from flint.types.arb_poly cimport arb_poly_set_list from flint.types.acb_poly cimport acb_poly_set_list from flint.types.arb cimport arb from flint.types.acb_poly cimport acb_poly diff --git a/src/flint/types/arb.pyx b/src/flint/types/arb.pyx index dd6a55d1..d456a110 100644 --- a/src/flint/types/arb.pyx +++ b/src/flint/types/arb.pyx @@ -5,7 +5,7 @@ from flint.flint_base.flint_context cimport getprec from flint.flint_base.flint_context cimport thectx from flint.flint_base.flint_base cimport flint_scalar from flint.utils.typecheck cimport typecheck -from flint.utils.conversion cimport chars_from_str, str_from_chars, _str_trunc +from flint.utils.conversion cimport chars_from_str, str_from_chars from flint.types.fmpz cimport fmpz_set_pylong from flint.types.arf cimport arf from flint.types.fmpq cimport fmpq diff --git a/src/flint/types/arb_poly.pyx b/src/flint/types/arb_poly.pyx index f0b2bbcc..6c69745d 100644 --- a/src/flint/types/arb_poly.pyx +++ b/src/flint/types/arb_poly.pyx @@ -14,7 +14,6 @@ from flint.types.acb_poly cimport acb_poly from flint.flintlib.arb cimport * from flint.flintlib.arb_poly cimport * -cimport cython cimport libc.stdlib cdef arb_poly_coerce_operands(x, y): diff --git a/src/flint/types/fmpq.pyx b/src/flint/types/fmpq.pyx index f9748619..669d79d2 100644 --- a/src/flint/types/fmpq.pyx +++ b/src/flint/types/fmpq.pyx @@ -5,7 +5,7 @@ from flint.types.fmpz cimport fmpz from flint.types.fmpz cimport any_as_fmpz from flint.flintlib.flint cimport FMPZ_UNKNOWN, FMPZ_TMP, FMPZ_REF -from flint.flintlib.fmpz cimport fmpz_set, fmpz_one, fmpz_t +from flint.flintlib.fmpz cimport fmpz_set, fmpz_one from flint.flintlib.fmpz cimport fmpz_is_zero, fmpz_sgn from flint.flintlib.fmpz cimport fmpz_fdiv_q, fmpz_bits from flint.flintlib.fmpz cimport fmpz_cdiv_q diff --git a/src/flint/types/fmpq_mat.pyx b/src/flint/types/fmpq_mat.pyx index f9b8a1c3..b379b83e 100644 --- a/src/flint/types/fmpq_mat.pyx +++ b/src/flint/types/fmpq_mat.pyx @@ -2,13 +2,11 @@ from flint.flint_base.flint_base cimport flint_mat from flint.utils.typecheck cimport typecheck from flint.types.fmpq_poly cimport fmpq_poly from flint.types.fmpq cimport any_as_fmpq -from flint.types.fmpz_poly cimport fmpz_poly -from flint.types.fmpq_poly cimport fmpq_poly_set_list 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_poly cimport fmpq_poly_init, fmpq_poly_clear +from flint.flintlib.fmpq_poly cimport fmpq_poly_init from flint.flintlib.fmpq_mat cimport * cimport cython diff --git a/src/flint/types/fmpq_mpoly.pyx b/src/flint/types/fmpq_mpoly.pyx index d13d1c0d..14bc9098 100644 --- a/src/flint/types/fmpq_mpoly.pyx +++ b/src/flint/types/fmpq_mpoly.pyx @@ -36,7 +36,6 @@ from flint.flintlib.fmpq_mpoly cimport ( fmpq_mpoly_gen, fmpq_mpoly_get_coeff_fmpq_fmpz, fmpq_mpoly_get_str_pretty, - fmpq_mpoly_get_term, fmpq_mpoly_get_term_coeff_fmpq, fmpq_mpoly_get_term_exp_fmpz, fmpq_mpoly_integral, @@ -48,7 +47,6 @@ from flint.flintlib.fmpq_mpoly cimport ( fmpq_mpoly_pow_fmpz, fmpq_mpoly_push_term_fmpq_ffmpz, fmpq_mpoly_reduce, - fmpq_mpoly_scalar_div_fmpq, fmpq_mpoly_scalar_mul_fmpq, fmpq_mpoly_set, fmpq_mpoly_set_coeff_fmpq_fmpz, diff --git a/src/flint/types/fmpz_mat.pyx b/src/flint/types/fmpz_mat.pyx index d8d68f27..82501a29 100644 --- a/src/flint/types/fmpz_mat.pyx +++ b/src/flint/types/fmpz_mat.pyx @@ -4,7 +4,6 @@ from flint.types.fmpz cimport fmpz from flint.types.fmpz_poly cimport fmpz_poly from flint.types.fmpq_mat cimport fmpq_mat from flint.types.fmpz cimport any_as_fmpz -from flint.types.fmpq cimport fmpq from flint.pyflint cimport global_random_state from flint.types.fmpq cimport any_as_fmpq cimport cython diff --git a/src/flint/types/fmpz_mod.pyx b/src/flint/types/fmpz_mod.pyx index 7d134754..39c8316b 100644 --- a/src/flint/types/fmpz_mod.pyx +++ b/src/flint/types/fmpz_mod.pyx @@ -27,7 +27,6 @@ from flint.types.fmpz cimport( any_as_fmpz, fmpz_get_intlong ) -cimport cython cimport libc.stdlib from flint.utils.flint_exceptions import DomainError diff --git a/src/flint/types/fmpz_mod_mat.pyx b/src/flint/types/fmpz_mod_mat.pyx index 9722cecf..f4aac95f 100644 --- a/src/flint/types/fmpz_mod_mat.pyx +++ b/src/flint/types/fmpz_mod_mat.pyx @@ -38,9 +38,6 @@ from flint.flint_base.flint_base cimport ( from flint.types.fmpz cimport ( fmpz, ) -from flint.types.nmod cimport ( - nmod, -) from flint.types.fmpz_mod cimport ( fmpz_mod_ctx, fmpz_mod, diff --git a/src/flint/types/fmpz_mod_mpoly.pyx b/src/flint/types/fmpz_mod_mpoly.pyx index 1326624c..0ef2877b 100644 --- a/src/flint/types/fmpz_mod_mpoly.pyx +++ b/src/flint/types/fmpz_mod_mpoly.pyx @@ -35,7 +35,6 @@ from flint.flintlib.fmpz_mod_mpoly cimport ( fmpz_mod_mpoly_gen, fmpz_mod_mpoly_get_coeff_fmpz_fmpz, fmpz_mod_mpoly_get_str_pretty, - fmpz_mod_mpoly_get_term, fmpz_mod_mpoly_get_term_coeff_fmpz, fmpz_mod_mpoly_get_term_exp_fmpz, fmpz_mod_mpoly_is_one, diff --git a/src/flint/types/fmpz_mpoly.pyx b/src/flint/types/fmpz_mpoly.pyx index b5390cbc..c7a3528e 100644 --- a/src/flint/types/fmpz_mpoly.pyx +++ b/src/flint/types/fmpz_mpoly.pyx @@ -44,7 +44,6 @@ from flint.flintlib.fmpz_mpoly cimport ( fmpz_mpoly_pow_fmpz, fmpz_mpoly_push_term_fmpz_ffmpz, fmpz_mpoly_reduction_primitive_part, - fmpz_mpoly_scalar_divides_fmpz, fmpz_mpoly_scalar_mul_fmpz, fmpz_mpoly_set, fmpz_mpoly_set_coeff_fmpz_fmpz, diff --git a/src/flint/types/fmpz_poly.pyx b/src/flint/types/fmpz_poly.pyx index 37eedcb7..07052c4e 100644 --- a/src/flint/types/fmpz_poly.pyx +++ b/src/flint/types/fmpz_poly.pyx @@ -8,7 +8,6 @@ from flint.types.fmpz cimport fmpz_set_python from flint.types.fmpz cimport any_as_fmpz from flint.types.fmpz cimport fmpz from flint.types.fmpq cimport any_as_fmpq -from flint.types.fmpq cimport fmpq from flint.types.fmpq_poly cimport fmpq_poly from flint.types.fmpq_poly cimport any_as_fmpq_poly from flint.types.acb cimport acb diff --git a/src/flint/types/fmpz_vec.pyx b/src/flint/types/fmpz_vec.pyx index 365a1d38..6f8b2044 100644 --- a/src/flint/types/fmpz_vec.pyx +++ b/src/flint/types/fmpz_vec.pyx @@ -1,11 +1,7 @@ from flint.flintlib.fmpz cimport fmpz_struct, fmpz_set, fmpz_init_set -from flint.flintlib.flint cimport slong from flint.flintlib.fmpz_vec cimport _fmpz_vec_init, _fmpz_vec_clear from flint.types.fmpz cimport fmpz, any_as_fmpz -from flint.types.fmpz_mod cimport fmpz_mod - -from flint.utils.typecheck cimport typecheck cimport libc.stdlib diff --git a/src/flint/types/nmod.pyx b/src/flint/types/nmod.pyx index 93093ca9..68796c4f 100644 --- a/src/flint/types/nmod.pyx +++ b/src/flint/types/nmod.pyx @@ -7,7 +7,7 @@ from flint.types.fmpq cimport fmpq from flint.flintlib.flint cimport ulong from flint.flintlib.fmpz cimport fmpz_t -from flint.flintlib.nmod cimport nmod_pow_fmpz, nmod_inv +from flint.flintlib.nmod cimport nmod_pow_fmpz from flint.flintlib.nmod_vec cimport * from flint.flintlib.fmpz cimport fmpz_fdiv_ui, fmpz_init, fmpz_clear from flint.flintlib.fmpz cimport fmpz_set_ui, fmpz_get_ui diff --git a/src/flint/types/nmod_mpoly.pyx b/src/flint/types/nmod_mpoly.pyx index a29b58d6..54ed769e 100644 --- a/src/flint/types/nmod_mpoly.pyx +++ b/src/flint/types/nmod_mpoly.pyx @@ -9,7 +9,7 @@ from flint.flint_base.flint_base import Ordering from flint.utils.typecheck cimport typecheck from flint.utils.flint_exceptions import DomainError, IncompatibleContextError -from flint.types.fmpz cimport any_as_fmpz, fmpz +from flint.types.fmpz cimport fmpz from flint.types.fmpz_vec cimport fmpz_vec from flint.types.fmpz_mod cimport fmpz_mod @@ -38,7 +38,6 @@ from flint.flintlib.nmod_mpoly cimport ( nmod_mpoly_gen, nmod_mpoly_get_coeff_ui_fmpz, nmod_mpoly_get_str_pretty, - nmod_mpoly_get_term, nmod_mpoly_get_term_coeff_ui, nmod_mpoly_get_term_exp_fmpz, nmod_mpoly_is_one, diff --git a/src/flint/types/nmod_poly.pyx b/src/flint/types/nmod_poly.pyx index 853521ff..51518266 100644 --- a/src/flint/types/nmod_poly.pyx +++ b/src/flint/types/nmod_poly.pyx @@ -11,7 +11,6 @@ from flint.flintlib.nmod_vec cimport * from flint.flintlib.nmod_poly cimport * from flint.flintlib.nmod_poly_factor cimport * from flint.flintlib.fmpz_poly cimport fmpz_poly_get_nmod_poly -from flint.flintlib.ulong_extras cimport n_gcdinv from flint.utils.flint_exceptions import DomainError From 73812b6e4d4044844df32e7f378854f358e02240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 30 Aug 2024 21:28:00 +0200 Subject: [PATCH 4/5] move cython-lint config to pyproject --- .github/workflows/lint.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1347b100..272cc1a6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,4 +23,4 @@ jobs: - name: cython-lint run: | - cython-lint --ignore=E114,E117,E127,E128,E129,E202,E221,E222,E231,E261,E262,E265,E302,E303,E306,E501,E701,E703,E711,E722,E731,E741,E743,W291,W293,W391,W605 src/ + cython-lint src/ diff --git a/pyproject.toml b/pyproject.toml index 6885d4cb..e9cf4d80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ build-backend = "mesonpy" [tool.cython-lint] max-line-length = 120 -ignore = ['E225', 'E231', 'E501', 'E741'] +ignore = ['E114','E117','E127','E128','E129','E202','E221','E222','E231','E261','E262','E265','E302','E303','E306','E501','E701','E703','E711','E722','E731','E741','E743','W291','W293','W391','W605'] exclude = 'src/flint/flintlib/.*' [tool.spin] From 96a6f0ec9566f901a1b00a309f7c0bb1c9e12630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 30 Aug 2024 21:32:48 +0200 Subject: [PATCH 5/5] some codes are fixed already --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e9cf4d80..c67cefa9 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','E302','E303','E306','E501','E701','E703','E711','E722','E731','E741','E743','W291','W293','W391','W605'] +ignore = ['E114','E117','E127','E128','E129','E202','E221','E222','E231','E261','E262','E265','E302','E303','E306','E501','E701','E703','E711','E722','E731','E741','E743','W391'] exclude = 'src/flint/flintlib/.*' [tool.spin]