Skip to content

Commit

Permalink
gh-38263: partial care for empty lines in pyx in rings ; activate E30…
Browse files Browse the repository at this point in the history
…2 in pyx

    
this is fixing blank lines issues in pyx files in `rings` folder ; and
activating the check for pycodestyle  E302 in all pyx files

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
    
URL: #38263
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Jul 20, 2024
2 parents f1477ef + dd4b51d commit 6f913d4
Show file tree
Hide file tree
Showing 24 changed files with 34 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/sage/rings/complex_interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ cdef class ComplexIntervalFieldElement(FieldElement):
"""
raise TypeError


def _sage_input_(self, sib, coerce):
r"""
Produce an expression which will reproduce this value when evaluated.
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/finite_rings/element_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from sage.rings.integer_ring import ZZ
from sage.rings.integer import Integer
from sage.misc.superseded import deprecated_function_alias


def is_FiniteFieldElement(x):
"""
Return ``True`` if ``x`` is a finite field element.
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/finite_rings/element_givaro.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement):
"""
return unpickle_FiniteField_givaroElement,(self.parent(),self.element)


def unpickle_FiniteField_givaroElement(parent, int x):
"""
TESTS::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/element_ntl_gf2e.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ cdef class FiniteField_ntl_gf2eElement(FinitePolyExtElement):
cdef int pow = n/d
return f if pow == 1 else f**pow


def minpoly(self, var='x'):
r"""
Return the minimal polynomial of ``self``, which is the smallest
Expand Down Expand Up @@ -1302,6 +1301,7 @@ cdef class FiniteField_ntl_gf2eElement(FinitePolyExtElement):
x = pari.fflog(self, base, (base_order, fac))
return Integer(x)


def unpickleFiniteField_ntl_gf2eElement(parent, elem):
"""
EXAMPLES::
Expand Down
3 changes: 0 additions & 3 deletions src/sage/rings/finite_rings/hom_finite_field_givaro.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ cdef class SectionFiniteFieldHomomorphism_givaro(SectionFiniteFieldHomomorphism_

self._codomain_cache = (<FiniteField_givaroElement>(self._codomain.gen()))._cache


cpdef Element _call_(self, x):
"""
TESTS::
Expand Down Expand Up @@ -181,7 +180,6 @@ cdef class FiniteFieldHomomorphism_givaro(FiniteFieldHomomorphism_generic):
self._order_domain = domain.cardinality() - 1
self._order_codomain = codomain.cardinality() - 1


cpdef Element _call_(self, x):
"""
TESTS::
Expand Down Expand Up @@ -228,7 +226,6 @@ cdef class FrobeniusEndomorphism_givaro(FrobeniusEndomorphism_finite_field):
raise TypeError("The domain is not an instance of FiniteField_givaro")
FrobeniusEndomorphism_finite_field.__init__(self, domain, power)


def fixed_field(self):
"""
Return the fixed field of ``self``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/fraction_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ cdef class FractionFieldElement(FieldElement):
"""
return self._denominator


def is_square(self,root=False):
"""
Return whether or not ``self`` is a perfect square.
Expand Down Expand Up @@ -1286,6 +1285,7 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement):
super(self.__class__, self).reduce()
self.normalize_leading_coefficients()


def make_element(parent, numerator, denominator):
"""
Used for unpickling :class:`FractionFieldElement` objects (and subclasses).
Expand Down
5 changes: 0 additions & 5 deletions src/sage/rings/laurent_series_ring_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ cdef class LaurentSeries(AlgebraElement):
elif parent is not f.parent():
f = parent._power_series_ring(f)


# self is that t^n * u:
if not f:
if n is infinity:
Expand Down Expand Up @@ -822,7 +821,6 @@ cdef class LaurentSeries(AlgebraElement):
# 3. Subtract
return type(self)(self._parent, f1 - f2, m)


def add_bigoh(self, prec):
"""
Return the truncated series at chosen precision ``prec``.
Expand Down Expand Up @@ -1564,7 +1562,6 @@ cdef class LaurentSeries(AlgebraElement):
"""
return multi_derivative(self, args)


def _derivative(self, var=None):
"""
The formal derivative of this Laurent series with respect to var.
Expand Down Expand Up @@ -1624,7 +1621,6 @@ cdef class LaurentSeries(AlgebraElement):
u = self._parent._power_series_ring(v, self.__u.prec())
return type(self)(self._parent, u, n-1)


def integral(self):
r"""
The formal integral of this Laurent series with 0 constant term.
Expand Down Expand Up @@ -1682,7 +1678,6 @@ cdef class LaurentSeries(AlgebraElement):
raise ArithmeticError("Coefficients of integral cannot be coerced into the base ring")
return type(self)(self._parent, u, n+1)


def nth_root(self, long n, prec=None):
r"""
Return the ``n``-th root of this Laurent power series.
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/polynomial/cyclotomic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ try:
except ImportError:
pass


def cyclotomic_coeffs(nn, sparse=None):
"""
Return the coefficients of the `n`-th cyclotomic polynomial
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/polynomial/hilbert.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ cdef make_children(Node D, tuple w):
# It may be a good idea to form the product of some of the most
# frequent variables. But this isn't implemented yet. TODO?


def first_hilbert_series(I, grading=None, return_grading=False):
"""
Return the first Hilbert series of the given monomial ideal.
Expand Down Expand Up @@ -550,6 +551,7 @@ def first_hilbert_series(I, grading=None, return_grading=False):
fmpz_poly_add(fhs._poly, AN.LMult, AN.RMult)
got_result = True


def hilbert_poincare_series(I, grading=None):
r"""
Return the Hilbert Poincaré series of the given monomial ideal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ cdef ideal *sage_ideal_to_singular_ideal(I) except NULL:
raise TypeError("All generators must be of type MPolynomial_libsingular.")
return i


def kbase_libsingular(I, degree=None):
"""
SINGULAR's ``kbase()`` algorithm.
Expand Down Expand Up @@ -201,6 +202,7 @@ def kbase_libsingular(I, degree=None):

return res


def std_libsingular(I):
"""
SINGULAR's ``std()`` algorithm.
Expand All @@ -224,7 +226,6 @@ def std_libsingular(I):

idSkipZeroes(result)


id_Delete(&i,r)

res = singular_ideal_to_sage_sequence(result,r,I.ring())
Expand Down Expand Up @@ -272,6 +273,7 @@ def slimgb_libsingular(I):
id_Delete(&result,r)
return res


def interred_libsingular(I):
"""
SINGULAR's ``interred()`` command.
Expand Down Expand Up @@ -318,7 +320,6 @@ def interred_libsingular(I):
sig_off()
singular_options = bck


# divide head by coefficients
if r.cf.type != n_Z and r.cf.type != n_Znm and r.cf.type != n_Zn and r.cf.type != n_Z2m :
for j from 0 <= j < IDELEMS(result):
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
M.append(new_MP(self, p_Copy(tempvector, _ring)))
return M


def unpickle_MPolynomialRing_libsingular(base_ring, names, term_order):
"""
inverse function for ``MPolynomialRing_libsingular.__reduce__``
Expand Down
2 changes: 0 additions & 2 deletions src/sage/rings/polynomial/polynomial_compiled.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ cdef class CompiledPolynomialFunction:
The r == 0 case in step 3 is equivalent to binary exponentiation.
"""


cdef int m,n,k,r,half
cdef generic_pd T,N,H
cdef dummy_pd M
Expand Down
5 changes: 4 additions & 1 deletion src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11554,7 +11554,6 @@ cdef class Polynomial(CommutativePolynomial):
phi = SpecializationMorphism(self._parent,D)
return phi(self)


def _log_series(self, long n):
r"""
Return the power series expansion of logarithm of this polynomial,
Expand Down Expand Up @@ -11711,6 +11710,7 @@ cdef class Polynomial(CommutativePolynomial):
"""
raise NotImplementedError


# ----------------- inner functions -------------
# Cython can't handle function definitions inside other function

Expand Down Expand Up @@ -11766,6 +11766,7 @@ cdef list do_schoolbook_product(list x, list y, Py_ssize_t deg):
coeffs[k] = sum
return coeffs


@cython.boundscheck(False)
@cython.wraparound(False)
@cython.overflowcheck(False)
Expand Down Expand Up @@ -11848,6 +11849,7 @@ cdef list do_karatsuba_different_size(list left, list right, Py_ssize_t K_thresh
output.extend(carry[n-1:])
return output


@cython.boundscheck(False)
@cython.wraparound(False)
@cython.overflowcheck(False)
Expand Down Expand Up @@ -12581,6 +12583,7 @@ cdef class Polynomial_generic_dense(Polynomial):
self._coeffs = self._coeffs[:n]
return self


def make_generic_polynomial(parent, coeffs):
return parent(coeffs)

Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/polynomial/polynomial_gf2x.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def GF2X_BuildIrred_list(n):
GF2X_BuildIrred(f, int(n))
return [GF2(not GF2_IsZero(GF2X_coeff(f, i))) for i in range(n + 1)]


def GF2X_BuildSparseIrred_list(n):
"""
Return the list of coefficients of an irreducible polynomial of
Expand All @@ -330,6 +331,7 @@ def GF2X_BuildSparseIrred_list(n):
GF2X_BuildSparseIrred(f, int(n))
return [GF2(not GF2_IsZero(GF2X_coeff(f, i))) for i in range(n + 1)]


def GF2X_BuildRandomIrred_list(n):
"""
Return the list of coefficients of an irreducible polynomial of
Expand Down
7 changes: 4 additions & 3 deletions src/sage/rings/polynomial/polynomial_number_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ We can also construct polynomials over relative number fields::
1
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2014 Luis Felipe Tabera Alonso <[email protected]>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.rings.polynomial.polynomial_element_generic import Polynomial_generic_dense_field
from sage.rings.rational_field import QQ
from sage.structure.element import coerce_binop
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing


class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field):
"""
Class of dense univariate polynomials over an absolute number field.
Expand Down
1 change: 0 additions & 1 deletion src/sage/rings/polynomial/polynomial_rational_flint.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ cdef class Polynomial_rational_flint(Polynomial):
fmpq_poly_set_si(res._poly, int(x))
return res


def __cinit__(self):
"""
Initialises the underlying data structure.
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/polynomial/weil/weil_polynomials.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ cdef class dfs_manager:
raise RuntimeError("Node limit ({0:%d}) exceeded".format(self.node_limit))
return ans


class WeilPolynomials_iter():
r"""
Iterator created by WeilPolynomials.
Expand Down
1 change: 0 additions & 1 deletion src/sage/rings/power_series_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ cdef class PowerSeries_mpoly(PowerSeries):
prec = prec,
check =True)


def __iter__(self):
"""
Return an iterator over the coefficients of this power series.
Expand Down
2 changes: 0 additions & 2 deletions src/sage/rings/power_series_ring_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ cdef class PowerSeries(AlgebraElement):
s += " + %s"%bigoh
return s.lstrip(" ")


def truncate(self, prec=infinity):
"""
The polynomial obtained from power series by truncation.
Expand Down Expand Up @@ -2725,7 +2724,6 @@ cdef class PowerSeries(AlgebraElement):
"""
return multi_derivative(self, args)


def __setitem__(self, n, value):
"""
Called when an attempt is made to change a power series.
Expand Down
6 changes: 2 additions & 4 deletions src/sage/rings/rational.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ from sage.structure.richcmp cimport rich_to_bool_sgn

RealNumber_classes = ()


def _register_real_number_class(cls):
r"""
Register ``cls``.
Expand Down Expand Up @@ -1580,7 +1581,6 @@ cdef class Rational(sage.structure.element.FieldElement):
a, b = K.pari_bnf(proof=proof).bnfisnorm(self, flag=extra_primes)
return K(a), Rational(b)


def is_perfect_power(self, expected_value=False):
r"""
Return ``True`` if ``self`` is a perfect power.
Expand Down Expand Up @@ -3560,7 +3560,6 @@ cdef class Rational(sage.structure.element.FieldElement):
else:
return sage.rings.infinity.infinity


def multiplicative_order(self):
"""
Return the multiplicative order of ``self``.
Expand Down Expand Up @@ -3633,10 +3632,9 @@ cdef class Rational(sage.structure.element.FieldElement):
"""
return True

#Function alias for checking if the number is a integer. Added to solve issue 15500
# Function alias for checking if the number is a integer. Added to solve issue 15500
is_integer = is_integral


def is_S_integral(self, S=[]):
r"""
Determine if the rational number is ``S``-integral.
Expand Down
8 changes: 6 additions & 2 deletions src/sage/rings/sum_of_squares.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ cdef int three_squares_c(uint_fast32_t n, uint_fast32_t res[3]) noexcept:

return 1


def two_squares_pyx(uint32_t n):
r"""
Return a pair of non-negative integers ``(i,j)`` such that `i^2 + j^2 = n`.
Expand Down Expand Up @@ -184,7 +185,8 @@ def two_squares_pyx(uint32_t n):
return (integer.smallInteger(i[0]), integer.smallInteger(i[1]))
sig_off()

raise ValueError("%d is not a sum of 2 squares"%n)
raise ValueError("%d is not a sum of 2 squares" % n)


def is_sum_of_two_squares_pyx(uint32_t n):
r"""
Expand Down Expand Up @@ -214,6 +216,7 @@ def is_sum_of_two_squares_pyx(uint32_t n):
sig_off()
return False


def three_squares_pyx(uint32_t n):
r"""
If ``n`` is a sum of three squares return a 3-tuple ``(i,j,k)`` of Sage integers
Expand Down Expand Up @@ -266,7 +269,8 @@ def three_squares_pyx(uint32_t n):
return (integer.smallInteger(i[0]), integer.smallInteger(i[1]), integer.smallInteger(i[2]))
sig_off()

raise ValueError("%d is not a sum of 3 squares"%n)
raise ValueError("%d is not a sum of 3 squares" % n)


def four_squares_pyx(uint32_t n):
r"""
Expand Down
Loading

0 comments on commit 6f913d4

Please sign in to comment.