Skip to content

Commit

Permalink
Trac #33667: fix and activate pycodestyle E703 in pyx files
Browse files Browse the repository at this point in the history
namely, no need for final `;` at the end of lines

plus a few similar pycodestyle changes in pyx files inside combinat/

URL: https://trac.sagemath.org/33667
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed May 22, 2022
2 parents 63db311 + 7d3fd94 commit 6ef564d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 27 deletions.
21 changes: 14 additions & 7 deletions src/sage/combinat/combinat_cython.pyx
Expand Up @@ -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)
Expand Down Expand Up @@ -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]:
Expand All @@ -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]:
Expand All @@ -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]:
Expand All @@ -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]:
Expand All @@ -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]:
Expand Down
4 changes: 3 additions & 1 deletion src/sage/combinat/debruijn_sequence.pyx
Expand Up @@ -101,14 +101,16 @@ 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)
for j in range((a[t - p] + 1), (k)):
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
Expand Down
3 changes: 2 additions & 1 deletion src/sage/combinat/designs/gen_quadrangles_with_spread.pyx
Expand Up @@ -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]])

Expand Down
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/matrices/dancing_links.pyx
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion src/sage/combinat/words/word_char.pyx
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions src/sage/libs/giac/giac.pyx
Expand Up @@ -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
#############################################################
Expand Down Expand Up @@ -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??)
Expand Down
16 changes: 8 additions & 8 deletions src/sage/libs/singular/singular.pyx
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -1188,7 +1188,7 @@ cdef number *sa2si_NF(object elem, ring *_ring):
cdef char **_ext_names
_ext_names = <char**>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

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/integer_mod.pyx
Expand Up @@ -2174,7 +2174,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
mpz_add(x.value, self.value, (<IntegerMod_gmp>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):
"""
Expand All @@ -2189,7 +2189,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
mpz_sub(x.value, self.value, (<IntegerMod_gmp>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):
"""
Expand Down
1 change: 1 addition & 0 deletions src/tox.ini
Expand Up @@ -107,6 +107,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
Expand Down

0 comments on commit 6ef564d

Please sign in to comment.