From 7d3fd94853b5ae08ebb7ab979a97536a7f988854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 10 Apr 2022 10:25:25 +0200 Subject: [PATCH] fix and activate pycodestyle E703 in pyx files --- src/sage/combinat/combinat_cython.pyx | 21 ++++++++++++------- src/sage/combinat/debruijn_sequence.pyx | 4 +++- .../designs/gen_quadrangles_with_spread.pyx | 3 ++- .../orthogonal_arrays_find_recursive.pyx | 3 ++- src/sage/combinat/matrices/dancing_links.pyx | 4 ++-- src/sage/combinat/words/word_char.pyx | 4 +++- src/sage/libs/giac/giac.pyx | 7 +++---- src/sage/libs/singular/singular.pyx | 16 +++++++------- src/sage/rings/finite_rings/integer_mod.pyx | 4 ++-- src/tox.ini | 1 + 10 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/sage/combinat/combinat_cython.pyx b/src/sage/combinat/combinat_cython.pyx index cc9ba2ba501..3d8e8042311 100644 --- a/src/sage/combinat/combinat_cython.pyx +++ b/src/sage/combinat/combinat_cython.pyx @@ -481,12 +481,14 @@ cdef void _linear_extension_switch(list _le, list _a, list _b, list _is_plus, Py if i == -1: _is_plus[0] = not _is_plus[0] else: - a = _a[i]; b = _b[i] + a = _a[i] + b = _b[i] a_index = _le.index(a) b_index = _le.index(b) _le[a_index] = b _le[b_index] = a - _b[i] = a; _a[i] = b + _b[i] = a + _a[i] = b @cython.wraparound(False) @cython.boundscheck(False) @@ -572,7 +574,8 @@ def _linear_extension_gen(_D, list _le, list _a, list _b, list _is_plus, Py_ssiz while _linear_extension_right_b(_D, _le, _a, _b, i): mrb += 1 # move_right - index = _le.index(_b[i]); index1 = index + 1 + index = _le.index(_b[i]) + index1 = index + 1 _le[index] = _le[index1] _le[index1] = _b[i] if _is_plus[0]: @@ -585,7 +588,8 @@ def _linear_extension_gen(_D, list _le, list _a, list _b, list _is_plus, Py_ssiz typical = True mra += 1 # move_right - index = _le.index(_a[i]); index1 = index+1 + index = _le.index(_a[i]) + index1 = index+1 _le[index] = _le[index1] _le[index1] = _a[i] if _is_plus[0]: @@ -607,7 +611,8 @@ def _linear_extension_gen(_D, list _le, list _a, list _b, list _is_plus, Py_ssiz mla = mra + 1 for _ in range(mla): # move_left - index = _le.index(_a[i]); index1 = index-1 + index = _le.index(_a[i]) + index1 = index-1 _le[index] = _le[index1] _le[index1] = _a[i] if _is_plus[0]: @@ -618,7 +623,8 @@ def _linear_extension_gen(_D, list _le, list _a, list _b, list _is_plus, Py_ssiz if typical and (mrb % 2 == 1): # move_left - index = _le.index(_a[i]); index1 = index-1 + index = _le.index(_a[i]) + index1 = index-1 _le[index] = _le[index1] _le[index1] = _a[i] if _is_plus[0]: @@ -631,7 +637,8 @@ def _linear_extension_gen(_D, list _le, list _a, list _b, list _is_plus, Py_ssiz yield e for _ in range(mrb): # move_left - index = _le.index(_b[i]); index1 = index-1 + index = _le.index(_b[i]) + index1 = index-1 _le[index] = _le[index1] _le[index1] = _b[i] if _is_plus[0]: diff --git a/src/sage/combinat/debruijn_sequence.pyx b/src/sage/combinat/debruijn_sequence.pyx index 9dbf16238ee..6b96c2f6a8b 100644 --- a/src/sage/combinat/debruijn_sequence.pyx +++ b/src/sage/combinat/debruijn_sequence.pyx @@ -101,7 +101,8 @@ cdef gen(int t, int p, k, n): cdef int j if t > n: if n % p == 0: - for j in range(1, p + 1): sequence.append(a[j]) + for j in range(1, p + 1): + sequence.append(a[j]) else: a[t] = a[t - p] gen(t + 1, p, k, n) @@ -109,6 +110,7 @@ cdef gen(int t, int p, k, n): a[t] = j gen(t + 1, t, k, n) + def is_debruijn_sequence(seq, k, n): r""" Given a sequence of integer elements in `0..k-1`, tests whether it diff --git a/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx b/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx index 4646caa80db..1d2035eeba0 100644 --- a/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx +++ b/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx @@ -103,7 +103,8 @@ def generalised_quadrangle_with_spread(const int s, const int t, raise RuntimeError(f"No GQ of order ({s}, {t}) exists") if s == 1 and t == 1: # we have a square - if existence: return True + if existence: + return True D = IncidenceStructure([[0, 1], [1, 2], [2, 3], [3, 0]]) return (D, [[0, 1], [2, 3]]) diff --git a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx index d1cd3561a1c..5743fc2f7d7 100644 --- a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +++ b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx @@ -801,10 +801,11 @@ cdef dict ioa_indexed_by_n_minus_x = {} for x in _QDM.itervalues(): for (n,_,_,u),(k,_) in x.items(): if u>1: - if not n in ioa_indexed_by_n_minus_x: + if n not in ioa_indexed_by_n_minus_x: ioa_indexed_by_n_minus_x[n] = [] ioa_indexed_by_n_minus_x[n].append((k,u)) + def int_as_sum(int value, list S, int k_max): r""" Return a tuple `(s_1, s_2, \ldots, s_k)` of less then `k_max` elements of `S` such diff --git a/src/sage/combinat/matrices/dancing_links.pyx b/src/sage/combinat/matrices/dancing_links.pyx index d3b406751d7..93859dce9b9 100644 --- a/src/sage/combinat/matrices/dancing_links.pyx +++ b/src/sage/combinat/matrices/dancing_links.pyx @@ -674,9 +674,9 @@ cdef class dancing_linksWrapper: else: return None - indices = [i for (i,row) in enumerate(self._rows) if column in row] + indices = [i for (i, row) in enumerate(self._rows) if column in row] for (args_kwds, val) in first_solution(indices): - if not val is None: + if val is not None: return val def all_solutions(self, ncpus=None, column=None): diff --git a/src/sage/combinat/words/word_char.pyx b/src/sage/combinat/words/word_char.pyx index 11bb29d1d1c..494976a9f92 100644 --- a/src/sage/combinat/words/word_char.pyx +++ b/src/sage/combinat/words/word_char.pyx @@ -534,7 +534,9 @@ cdef class WordDatatype_char(WordDatatype): if exp == float('inf'): from sage.rings.infinity import Infinity - fcn = lambda n: self[n % self.length()] + + def fcn(n): + return self[n % self.length()] return self._parent.shift()(fcn, datatype='callable') if exp < 0: diff --git a/src/sage/libs/giac/giac.pyx b/src/sage/libs/giac/giac.pyx index 6e7664f1151..b9811cae273 100644 --- a/src/sage/libs/giac/giac.pyx +++ b/src/sage/libs/giac/giac.pyx @@ -1926,8 +1926,7 @@ cdef gen pylongtogen(a) except +: # when cythonizing with cython 0.24: # g=-g gives an Invalid operand type for '-' (gen) g=GIAC_neg(g) - return g; - + return g ############################################################# @@ -2033,8 +2032,8 @@ class GiacFunctionNoEV(Pygen): ############################################################# # Some convenient settings ############################################################ -Pygen('printpow(1)').eval() ; # default power is ^ -Pygen('add_language(1)').eval(); # Add the french keywords in the giac library language. +Pygen('printpow(1)').eval() # default power is ^ +Pygen('add_language(1)').eval() # Add the french keywords in the giac library language. # FIXME: print I for sqrt(-1) instead of i # GIAC_try_parse_i(False,context_ptr); (does not work??) diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index 610435634df..f57126a6be4 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -783,7 +783,7 @@ cdef number *sa2si_GFqNTLGF2E(FFgf2eE elem, ring *_ring): apow2 = _ring.cf.cfMult(coeff, apow1,_ring.cf) n2 = _ring.cf.cfAdd(apow2, n1,_ring.cf) _ring.cf.cfDelete(&apow2, _ring.cf) - _ring.cf.cfDelete(&n1, _ring.cf); + _ring.cf.cfDelete(&n1, _ring.cf) n1 = n2 apow2 = _ring.cf.cfMult(apow1, a,_ring.cf) @@ -849,7 +849,7 @@ cdef number *sa2si_GFq_generic(object elem, ring *_ring): apow2 = _ring.cf.cfMult(coeff, apow1,_ring.cf) n2 = _ring.cf.cfAdd(apow2, n1,_ring.cf) _ring.cf.cfDelete(&apow2, _ring.cf) - _ring.cf.cfDelete(&n1, _ring.cf); + _ring.cf.cfDelete(&n1, _ring.cf) n1 = n2 apow2 = _ring.cf.cfMult(apow1, a,_ring.cf) @@ -938,7 +938,7 @@ cdef number *sa2si_transext_QQ(object elem, ring *_ring): cdef number *power cdef int ngens cdef int ex - cdef nMapFunc nMapFuncPtr = NULL; + cdef nMapFunc nMapFuncPtr = NULL if _ring != currRing: rChangeCurrRing(_ring) @@ -1057,7 +1057,7 @@ cdef number *sa2si_transext_FF(object elem, ring *_ring): cdef number *aux2 cdef int ngens cdef int ex - cdef nMapFunc nMapFuncPtr = NULL; + cdef nMapFunc nMapFuncPtr = NULL if _ring != currRing: rChangeCurrRing(_ring) @@ -1163,7 +1163,7 @@ cdef number *sa2si_NF(object elem, ring *_ring): cdef number *apow1 cdef number *apow2 - cdef nMapFunc nMapFuncPtr = NULL; + cdef nMapFunc nMapFuncPtr = NULL nMapFuncPtr = naSetMap(_ring.cf, currRing.cf) # choose correct mapping function @@ -1188,7 +1188,7 @@ cdef number *sa2si_NF(object elem, ring *_ring): cdef char **_ext_names _ext_names = omAlloc0(sizeof(char*)) _ext_names[0] = omStrDup(_name) - qqr = rDefault( 0, 1, _ext_names); + qqr = rDefault( 0, 1, _ext_names) rComplete(qqr,1) qqr.ShortOut = 0 @@ -1203,7 +1203,7 @@ cdef number *sa2si_NF(object elem, ring *_ring): apow2 = _ring.cf.cfMult(naCoeff, apow1,_ring.cf) n2 = _ring.cf.cfAdd(apow2, n1,_ring.cf) _ring.cf.cfDelete(&apow2, _ring.cf) - _ring.cf.cfDelete(&n1, _ring.cf); + _ring.cf.cfDelete(&n1, _ring.cf) _ring.cf.cfDelete(&naCoeff, _ring.cf) n1 = n2 @@ -1302,7 +1302,7 @@ cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring): cdef char *_name cdef char **_ext_names - cdef nMapFunc nMapFuncPtr = NULL; + cdef nMapFunc nMapFuncPtr = NULL if _ring.cf.type == n_Z2m: _d = long(d) diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index f8b9bacc4f6..3d285a017ac 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -2174,7 +2174,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): mpz_add(x.value, self.value, (right).value) if mpz_cmp(x.value, self.__modulus.sageInteger.value) >= 0: mpz_sub(x.value, x.value, self.__modulus.sageInteger.value) - return x; + return x cpdef _sub_(self, right): """ @@ -2189,7 +2189,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): mpz_sub(x.value, self.value, (right).value) if mpz_sgn(x.value) == -1: mpz_add(x.value, x.value, self.__modulus.sageInteger.value) - return x; + return x cpdef _neg_(self): """ diff --git a/src/tox.ini b/src/tox.ini index d68df4848bd..7a8e44c5011 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -90,6 +90,7 @@ description = # See https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes deps = pycodestyle commands = pycodestyle --select E111,E401,E701,E702,E703,W605,E711,E712,E713,E721,E722 {posargs:{toxinidir}/sage/} + pycodestyle --select E703 --filename *.pyx {posargs:{toxinidir}/sage/} [pycodestyle] max-line-length = 160