From 801c0686cd7ebba825f38e6bb2889098c7d46665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 9 Mar 2022 09:58:32 +0100 Subject: [PATCH] fix indentation E111 in some pyx files --- src/sage/arith/multi_modular.pyx | 6 +- src/sage/categories/action.pyx | 4 +- src/sage/combinat/degree_sequences.pyx | 29 +++---- src/sage/ext/fast_callable.pyx | 99 ++++++++++++----------- src/sage/graphs/bliss.pyx | 5 +- src/sage/graphs/distances_all_pairs.pyx | 2 +- src/sage/graphs/graph_coloring.pyx | 2 +- src/sage/graphs/strongly_regular_db.pyx | 2 +- src/sage/graphs/trees.pyx | 4 +- src/sage/interacts/library_cython.pyx | 6 +- src/sage/matrix/matrix0.pyx | 14 ++-- src/sage/matrix/matrix2.pyx | 6 +- src/sage/matrix/matrix_rational_dense.pyx | 2 +- src/sage/misc/cachefunc.pyx | 6 +- src/sage/modules/free_module_element.pyx | 2 +- src/sage/quadratic_forms/ternary.pyx | 33 ++++---- src/sage/rings/complex_arb.pyx | 2 +- src/sage/rings/rational.pyx | 7 +- src/sage/rings/tate_algebra_ideal.pyx | 10 +-- src/sage/structure/category_object.pyx | 2 +- src/sage/structure/coerce.pyx | 2 +- src/sage/symbolic/expression.pyx | 8 +- 22 files changed, 128 insertions(+), 125 deletions(-) diff --git a/src/sage/arith/multi_modular.pyx b/src/sage/arith/multi_modular.pyx index 3b79d3bd6fc..e99ffe7e32f 100644 --- a/src/sage/arith/multi_modular.pyx +++ b/src/sage/arith/multi_modular.pyx @@ -116,7 +116,7 @@ cdef class MultiModularBasis_base(object): """ sig_free(self.moduli) for i in range(self.n): - mpz_clear(self.partial_products[i]) + mpz_clear(self.partial_products[i]) sig_free(self.partial_products) sig_free(self.C) mpz_clear(self.product) @@ -487,9 +487,9 @@ cdef class MultiModularBasis_base(object): count = self.n * mpz_sizeinbase(height, 2) / mpz_sizeinbase(self.partial_products[self.n-1], 2) # an estimate count = max(min(count, self.n), 1) while count > 1 and mpz_cmp(height, self.partial_products[count-1]) < 0: - count -= 1 + count -= 1 while mpz_cmp(height, self.partial_products[count-1]) > 0: - count += 1 + count += 1 return count diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 64d372da5f6..0a2085f6f52 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -304,7 +304,7 @@ cdef class Action(Functor): return S def codomain(self): - return self.underlying_set() + return self.underlying_set() def domain(self): return self.underlying_set() @@ -454,7 +454,7 @@ cdef class PrecomposedAction(Action): if right_precomposition is not None: rco = right_precomposition._codomain if rco is not right: - right_precomposition = homset.Hom(rco, right).natural_map() * right_precomposition + right_precomposition = homset.Hom(rco, right).natural_map() * right_precomposition right = right_precomposition.domain() if action._is_left: Action.__init__(self, left, US, 1) diff --git a/src/sage/combinat/degree_sequences.pyx b/src/sage/combinat/degree_sequences.pyx index 6f5f91fbaa9..b8dbf876e3c 100644 --- a/src/sage/combinat/degree_sequences.pyx +++ b/src/sage/combinat/degree_sequences.pyx @@ -441,24 +441,25 @@ cdef init(int n): return sequences cdef inline add_seq(): - """ - This function is called whenever a sequence is found. + """ + This function is called whenever a sequence is found. + + Build the degree sequence corresponding to the current state of the + algorithm and adds it to the sequences list. + """ + global sequences + global N + global seq - Build the degree sequence corresponding to the current state of the - algorithm and adds it to the sequences list. - """ - global sequences - global N - global seq + cdef list s = [] + cdef int i, j - cdef list s = [] - cdef int i, j + for N > i >= 0: + for 0 <= j < seq[i]: + s.append(i) - for N > i >= 0: - for 0<= j < seq[i]: - s.append(i) + sequences.append(s) - sequences.append(s) cdef void enum(int k, int M): r""" diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index ad08d337a54..db1b84073df 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -1481,55 +1481,56 @@ cdef class ExpressionChoice(Expression): repr(self._iffalse)) cpdef _expression_binop_helper(s, o, op): - r""" - Make an Expression for (s op o). Either s or o (or both) must already - be an expression. - - EXAMPLES:: - - sage: from sage.ext.fast_callable import _expression_binop_helper, ExpressionTreeBuilder - sage: var('x,y') - (x, y) - sage: etb = ExpressionTreeBuilder(vars=(x,y)) - sage: x = etb(x) - - Now x is an Expression, but y is not. Still, all the following - cases work:: - - sage: _expression_binop_helper(x, x, operator.add) - add(v_0, v_0) - sage: _expression_binop_helper(x, y, operator.add) - add(v_0, v_1) - sage: _expression_binop_helper(y, x, operator.add) - add(v_1, v_0) - - """ - # The Cython way of handling operator overloading on cdef classes - # (which is inherited from Python) is quite annoying. Inside the - # code for a binary operator, you know that either the first or - # second argument (or both) is a member of your class, but you - # don't know which. - - # If there is an arithmetic operator between an Expression and - # a non-Expression, I want to convert the non-Expression into - # an Expression. But to do that, I need the ExpressionTreeBuilder - # from the Expression. - - cdef Expression self - cdef Expression other - - if not isinstance(o, Expression): - self = s - other = self._etb(o) - elif not isinstance(s, Expression): - other = o - self = other._etb(s) - else: - self = s - other = o - assert self._etb is other._etb - - return ExpressionCall(self._etb, op, [self, other]) + r""" + Make an Expression for (s op o). Either s or o (or both) must already + be an expression. + + EXAMPLES:: + + sage: from sage.ext.fast_callable import _expression_binop_helper, ExpressionTreeBuilder + sage: var('x,y') + (x, y) + sage: etb = ExpressionTreeBuilder(vars=(x,y)) + sage: x = etb(x) + + Now x is an Expression, but y is not. Still, all the following + cases work:: + + sage: _expression_binop_helper(x, x, operator.add) + add(v_0, v_0) + sage: _expression_binop_helper(x, y, operator.add) + add(v_0, v_1) + sage: _expression_binop_helper(y, x, operator.add) + add(v_1, v_0) + + """ + # The Cython way of handling operator overloading on cdef classes + # (which is inherited from Python) is quite annoying. Inside the + # code for a binary operator, you know that either the first or + # second argument (or both) is a member of your class, but you + # don't know which. + + # If there is an arithmetic operator between an Expression and + # a non-Expression, I want to convert the non-Expression into + # an Expression. But to do that, I need the ExpressionTreeBuilder + # from the Expression. + + cdef Expression self + cdef Expression other + + if not isinstance(o, Expression): + self = s + other = self._etb(o) + elif not isinstance(s, Expression): + other = o + self = other._etb(s) + else: + self = s + other = o + assert self._etb is other._etb + + return ExpressionCall(self._etb, op, [self, other]) + class IntegerPowerFunction(object): r""" diff --git a/src/sage/graphs/bliss.pyx b/src/sage/graphs/bliss.pyx index bf15833664c..e5c8ac0877f 100644 --- a/src/sage/graphs/bliss.pyx +++ b/src/sage/graphs/bliss.pyx @@ -861,8 +861,8 @@ cdef Graph *bliss_graph(G, partition, vert2int, int2vert): vert2int[v] = i int2vert[i] = v - for x,y in G.edge_iterator(labels=False): - g.add_edge(vert2int[x], vert2int[y]) + for x, y in G.edge_iterator(labels=False): + g.add_edge(vert2int[x], vert2int[y]) if partition: for i in range(1, len(partition)): @@ -870,6 +870,7 @@ cdef Graph *bliss_graph(G, partition, vert2int, int2vert): g.change_color(vert2int[v], i) return g + cdef Digraph *bliss_digraph(G, partition, vert2int, int2vert): r""" Return a bliss copy of a digraph G diff --git a/src/sage/graphs/distances_all_pairs.pyx b/src/sage/graphs/distances_all_pairs.pyx index 0dcd5d23049..20ed1524410 100644 --- a/src/sage/graphs/distances_all_pairs.pyx +++ b/src/sage/graphs/distances_all_pairs.pyx @@ -591,7 +591,7 @@ def is_distance_regular(G, parameters=False): for u in range(n): for v in range(n): if u == v: - continue + continue d = distance_matrix[u * n + v] if d == infinity: diff --git a/src/sage/graphs/graph_coloring.pyx b/src/sage/graphs/graph_coloring.pyx index f9a87450bd8..50cb529f95f 100644 --- a/src/sage/graphs/graph_coloring.pyx +++ b/src/sage/graphs/graph_coloring.pyx @@ -1190,7 +1190,7 @@ def b_coloring(g, k, value_only=True, solver=None, verbose=0, # a color class is used if and only if it has one b-vertex for i in range(k): - p.add_constraint(p.sum(b[w,i] for w in g) - is_used[i], min=0, max=0) + p.add_constraint(p.sum(b[w,i] for w in g) - is_used[i], min=0, max=0) # We want to maximize the number of used colors diff --git a/src/sage/graphs/strongly_regular_db.pyx b/src/sage/graphs/strongly_regular_db.pyx index cdbd9e3b345..d98a5f553c4 100644 --- a/src/sage/graphs/strongly_regular_db.pyx +++ b/src/sage/graphs/strongly_regular_db.pyx @@ -1341,7 +1341,7 @@ def is_unitary_dual_polar(int v,int k,int l,int mu): if p**t != q or t % 2: return if (r < 0 and q != -r - 1) or (s < 0 and q != -s - 1): - return + return t //= 2 # we have correct mu, negative eigenvalue, and q=p^(2t) if (v == (q**2*p**t + 1)*(q*p**t + 1) and diff --git a/src/sage/graphs/trees.pyx b/src/sage/graphs/trees.pyx index 8cb5d87778f..cd7734d8ebf 100644 --- a/src/sage/graphs/trees.pyx +++ b/src/sage/graphs/trees.pyx @@ -229,9 +229,9 @@ cdef class TreeIterator: if p <= h1: h1 = p - 1 if p <= r: - needr = 1 + needr = 1 elif p <= h2: - needh2 = 1 + needh2 = 1 elif l[h2 - 1] == l[h1 - 1] - 1 and n - h2 == r - h1: if p <= c: needc = 1 diff --git a/src/sage/interacts/library_cython.pyx b/src/sage/interacts/library_cython.pyx index 59fbc931e6b..205ea0a0b30 100644 --- a/src/sage/interacts/library_cython.pyx +++ b/src/sage/interacts/library_cython.pyx @@ -40,10 +40,12 @@ cpdef julia(ff_j, z, int iterations): 1.0 + 3.0*I """ for i in range(iterations): - z = ff_j(z) - if z.abs() > 2: break + z = ff_j(z) + if z.abs() > 2: + break return z + cpdef mandel(ff_m, z, int iterations): """ Helper function for the Mandelbrot Fractal interact example. diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index ff88dc2ed68..98d45d063e5 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -1434,7 +1434,7 @@ cdef class Matrix(sage.structure.element.Matrix): row_list = normalize_index(row_index, nrows) row_list_len = len(row_list) if row_list_len==0: - return + return if single_row and single_col and not no_col_index: self.set_unsafe(row, col, self._coerce_element(value)) @@ -4720,16 +4720,16 @@ cdef class Matrix(sage.structure.element.Matrix): [(0, 0), (1, 1)] """ x = self.fetch('nonzero_positions') - if not x is None: + if x is not None: if copy: return list(x) return x cdef Py_ssize_t i, j nzp = [] for i from 0 <= i < self._nrows: - for j from 0 <= j < self._ncols: - if not self.get_is_zero_unsafe(i,j): - nzp.append((i,j)) + for j from 0 <= j < self._ncols: + if not self.get_is_zero_unsafe(i, j): + nzp.append((i, j)) self.cache('nonzero_positions', nzp) if copy: return list(nzp) @@ -4971,9 +4971,9 @@ cdef class Matrix(sage.structure.element.Matrix): fac = o1.factor() S = sum((pi - 1) * pi**(ei - 1) for pi, ei in fac) if fac[0] == (2, 1): - impossible_order = not(S <= n + 1) + impossible_order = not(S <= n + 1) else: - impossible_order = not(S <= n) + impossible_order = not(S <= n) if impossible_order: return Infinity diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 3ec83f779e2..9c3ce5b961d 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -2163,7 +2163,7 @@ cdef class Matrix(Matrix1): if (level - i) % 2: d -= self.get_unsafe(level,level) * self._det_by_minors(level) else: - d += self.get_unsafe(level,level) * self._det_by_minors(level) + d += self.get_unsafe(level,level) * self._det_by_minors(level) # undo all our permutations to get us back to where we started for i from 0 <= i < level: self.swap_rows(level, i) @@ -7426,7 +7426,7 @@ cdef class Matrix(Matrix1): raise NotImplementedError("%s\nechelon form over %s not yet implemented"%(msg, self.base_ring())) for c from 0 <= c < self.ncols(): - for r from 0 <= r < self.nrows(): + for r from 0 <= r < self.nrows(): self.set_unsafe(r, c, d.get_unsafe(r,c)) self.clear_cache() self.cache('pivots', tuple(p)) @@ -8344,7 +8344,7 @@ cdef class Matrix(Matrix1): # me + nc and me + 1 such that no entry is present already in the matrix. S = [first_row[0] + ncols] + [None]*(ncols-1) for j in range(1, ncols): - S[j] = S[j - 1] if first_row[j] == first_row[j - 1] else S[j - 1] - 1 + S[j] = S[j - 1] if first_row[j] == first_row[j - 1] else S[j - 1] - 1 # If we want to sort the i-th row with respect to a symmetry determined # by S, then we will just sort the augmented row [[S[j], PM[i, j]] : # j in [1 .. nc]], S having lexicographic priority. diff --git a/src/sage/matrix/matrix_rational_dense.pyx b/src/sage/matrix/matrix_rational_dense.pyx index bfef0b60e49..6c632bc4d7f 100644 --- a/src/sage/matrix/matrix_rational_dense.pyx +++ b/src/sage/matrix/matrix_rational_dense.pyx @@ -381,7 +381,7 @@ cdef class Matrix_rational_dense(Matrix_dense): num, den = [str_to_bytes(n) for n in s.split('/')] if fmpz_set_str(fmpq_mat_entry_num(self._matrix, i, j), num, 32) or \ fmpz_set_str(fmpq_mat_entry_den(self._matrix, i, j), den, 32): - raise RuntimeError("invalid pickle data") + raise RuntimeError("invalid pickle data") else: s = str_to_bytes(s) if fmpz_set_str(fmpq_mat_entry_num(self._matrix, i, j), s, 32): diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index 7297edaaa66..96d75747dae 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -2223,7 +2223,7 @@ cdef class CachedMethodCallerNoArgs(CachedFunction): try: F = getattr(inst.__class__,f) except AttributeError: - F = getattr(inst,f) + F = getattr(inst,f) if isinstance(F,CachedFunction): f = F.f else: @@ -3634,8 +3634,8 @@ class FileCache(object): del self._cache[key] if os.path.exists(f + '.sobj'): os.remove(f + '.sobj') - if os.path.exists(f + '.key.sobj'): - os.remove(f + '.key.sobj') + if os.path.exists(f + '.key.sobj'): + os.remove(f + '.key.sobj') class DiskCachedFunction(CachedFunction): diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index bb4c895f9d5..93689cddf23 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -1590,7 +1590,7 @@ cdef class FreeModuleElement(Vector): # abstract base class for i in range(self._degree): ord = self[i].additive_order() if isinstance(ord, AnInfinity): - return ord + return ord v.append(ord) from sage.arith.all import lcm return lcm(v) diff --git a/src/sage/quadratic_forms/ternary.pyx b/src/sage/quadratic_forms/ternary.pyx index 80405d61158..168ef3392bb 100644 --- a/src/sage/quadratic_forms/ternary.pyx +++ b/src/sage/quadratic_forms/ternary.pyx @@ -44,9 +44,10 @@ def red_mfact(a,b): """ if a: - return (-b + abs(a))//(2*a) + return (-b + abs(a))//(2*a) else: - return 0 + return 0 + def _reduced_ternary_form_eisenstein_with_matrix(a1, a2, a3, a23, a13, a12): """ @@ -162,14 +163,14 @@ def _reduced_ternary_form_eisenstein_with_matrix(a1, a2, a3, a23, a13, a12): if (a12==0): s3=1 if s1: - M*=diagonal_matrix([-1,1,1]) - a23=-a23 + M*=diagonal_matrix([-1,1,1]) + a23=-a23 if s2: - M*=diagonal_matrix([1,-1,1]) - a13=-a13 + M*=diagonal_matrix([1,-1,1]) + a13=-a13 if s3: - M*=diagonal_matrix([1,1,-1]) - a12=-a12 + M*=diagonal_matrix([1,1,-1]) + a12=-a12 loop = not (abs(a23) <= a2 and abs(a13) <= a1 and abs(a12) <= a1 and a1+a2+a23+a13+a12>=0) @@ -344,11 +345,11 @@ def _reduced_ternary_form_eisenstein_without_matrix(a1, a2, a3, a23, a13, a12): if (a12==0): s3=1 if s1: - a23=-a23 + a23=-a23 if s2: - a13=-a13 + a13=-a13 if s3: - a12=-a12 + a12=-a12 loop = not (abs(a23) <= a2 and abs(a13) <= a1 and abs(a12) <= a1 and a1+a2+a23+a13+a12 >= 0) @@ -686,7 +687,7 @@ def _find_all_ternary_qf_by_level_disc(long long N, long long d): l=[] if (4*d)%N!=0: - raise ValueError("There are no ternary forms of this level and discriminant") + raise ValueError("There are no ternary forms of this level and discriminant") else: m=4*d//N @@ -824,14 +825,12 @@ def _find_a_ternary_qf_by_level_disc(long long N, long long d): cdef long long stu2 cdef long long mg - - - if (4*d)%N!=0: - raise ValueError("There are no ternary forms of this level and discriminant") + if (4*d)%N: + raise ValueError("There are no ternary forms of this level and discriminant") else: m=4*d//N - if (N**2)%d!=0: + if (N**2)%d: raise ValueError("There are no ternary forms of this level and discriminant") else: mu=N*N//d diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index f14febd6e98..0318e5867d7 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -2726,7 +2726,7 @@ cdef class ComplexBall(RingElement): cdef ComplexBall self = val cdef ComplexBall res = self._new() if is_small_python_int(shift): - acb_mul_2exp_si(res.value, self.value, PyInt_AS_LONG(shift)) + acb_mul_2exp_si(res.value, self.value, PyInt_AS_LONG(shift)) elif isinstance(shift, Integer): sig_on() fmpz_init(tmpz) diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 9d771c15f7c..db85e5ed887 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -960,11 +960,10 @@ cdef class Rational(sage.structure.element.FieldElement): """ if self.denom() == 1: return str(self.numer()) + if self < 0: + return "-\\frac{%s}{%s}" % (-self.numer(), self.denom()) else: - if self < 0: - return "-\\frac{%s}{%s}"%(-self.numer(), self.denom()) - else: - return "\\frac{%s}{%s}"%(self.numer(), self.denom()) + return "\\frac{%s}{%s}" % (self.numer(), self.denom()) def _symbolic_(self, sring): """ diff --git a/src/sage/rings/tate_algebra_ideal.pyx b/src/sage/rings/tate_algebra_ideal.pyx index 7226e89e3ec..e6560b2d862 100644 --- a/src/sage/rings/tate_algebra_ideal.pyx +++ b/src/sage/rings/tate_algebra_ideal.pyx @@ -1292,11 +1292,11 @@ def groebner_basis_vapote(I, prec, verbose=0, interrupt_red_with_val=False, inte else: i += 1 if verbose > 0: - if verbose > 1: - aft = " after minimization" - else: - aft = "" - print("%s elements in GB%s" % (len(gb), aft)) + if verbose > 1: + aft = " after minimization" + else: + aft = "" + print("%s elements in GB%s" % (len(gb), aft)) if verbose > 3: for g in gb: print("| %s" % g) diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index 334ee91430d..52abd7d918b 100644 --- a/src/sage/structure/category_object.pyx +++ b/src/sage/structure/category_object.pyx @@ -1013,7 +1013,7 @@ cpdef normalize_names(Py_ssize_t ngens, names): certify_names(names) if ngens >= 0 and len(names) != ngens: - raise IndexError("the number of names must equal the number of generators") + raise IndexError("the number of names must equal the number of generators") return tuple(names) diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 6829025345b..884e14b5ed7 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -1049,7 +1049,7 @@ cdef class CoercionModel: base = None for x in args: if not isinstance(x, Parent) and not isinstance(x, type): - x = parent(x) + x = parent(x) if base is None: base = x if isinstance(base, Parent) and (base).has_coerce_map_from(x): diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index b638420351c..c6d1c37f961 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -13981,13 +13981,13 @@ cdef operators compatible_relation(operators lop, operators rop) except