Skip to content

Commit b800a70

Browse files
author
Release Manager
committed
gh-39958: some care for unused variables in rings/polynomial/ pyx files This fixes all suggestions of cython-lint about unused variables in pyx files in `rings/polynomial/` ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #39958 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents c1a1bc7 + 10e0ebd commit b800a70

12 files changed

+31
-48
lines changed

src/sage/rings/polynomial/hilbert.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ cdef list quotient_by_var(list L, size_t index):
131131
Return the quotient of the ideal represented by ``L`` and the
132132
variable number ``index``.
133133
"""
134-
cdef ETuple m_j
135134
cdef list result = L[:len(L)] # creates a copy
136135
cdef size_t i
137136
for i in range(len(L)):
@@ -166,7 +165,6 @@ cdef bint HilbertBaseCase(Polynomial_integer_dense_flint fhs, Node D, tuple w) n
166165
Otherwiese, ``False`` is returned.
167166
"""
168167
cdef size_t i, j, exp
169-
cdef int e
170168
# First, the easiest cases:
171169
if not D.Id: # The zero ideal
172170
fmpz_poly_set_coeff_si(fhs._poly, 0, 1) # = PR(1)
@@ -227,7 +225,6 @@ cdef bint HilbertBaseCase(Polynomial_integer_dense_flint fhs, Node D, tuple w) n
227225

228226
easy = True
229227
cdef ETuple m2
230-
cdef list v
231228
for j in range(i+1, len(D.Id)):
232229
if (<ETuple>PyList_GET_ITEM(D.Id,j))._nonzero > 1:
233230
# i.e., another generator contains more than a single var
@@ -296,7 +293,7 @@ cdef make_children(Node D, tuple w):
296293
if ``D.Right`` is not ``None``.
297294
"""
298295
cdef size_t j, m
299-
cdef int i, ii
296+
cdef int i
300297
# Determine the variable that appears most often in the monomials.
301298
# If "most often" means "only once", then instead we choose a variable that is
302299
# guaranteed to appear in a composed monomial.

src/sage/rings/polynomial/multi_polynomial.pyx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ cdef class MPolynomial(CommutativePolynomial):
884884
except AttributeError:
885885
raise NotImplementedError
886886
else:
887-
q, r = quo_rem(other)
887+
_, r = quo_rem(other)
888888
return r
889889

890890
def change_ring(self, R):
@@ -2566,7 +2566,6 @@ cdef class MPolynomial(CommutativePolynomial):
25662566

25672567
prec = kwds.get('prec', 300)
25682568
return_conjugation = kwds.get('return_conjugation', True)
2569-
error_limit = kwds.get('error_limit', 0.000001)
25702569
emb = kwds.get('emb', None)
25712570

25722571
# getting a numerical approximation of the roots of our polynomial
@@ -2606,7 +2605,8 @@ cdef class MPolynomial(CommutativePolynomial):
26062605
# since we are searching anyway, don't need the 'true' reduced covariant
26072606
from sage.rings.polynomial.binary_form_reduce import smallest_poly
26082607
norm_type = kwds.get('norm_type', 'norm')
2609-
sm_F, sm_m = smallest_poly(self(tuple(M * vector([x,y]))), prec=prec, norm_type=norm_type, emb=emb)
2608+
_, sm_m = smallest_poly(self(tuple(M * vector([x, y]))), prec=prec,
2609+
norm_type=norm_type, emb=emb)
26102610
M = M*sm_m
26112611
else:
26122612
# solve the minimization problem for 'true' covariant
@@ -2631,7 +2631,7 @@ cdef class MPolynomial(CommutativePolynomial):
26312631
return (self(tuple(M * vector([x,y]))), M)
26322632
return self(tuple(M * vector([x,y])))
26332633

2634-
def is_unit(self):
2634+
def is_unit(self) -> bool:
26352635
r"""
26362636
Return ``True`` if ``self`` is a unit, that is, has a
26372637
multiplicative inverse.
@@ -2892,7 +2892,7 @@ cdef class MPolynomial(CommutativePolynomial):
28922892
return result(True)
28932893

28942894

2895-
def _is_M_convex_(points):
2895+
def _is_M_convex_(points) -> bool:
28962896
r"""
28972897
Return whether ``points`` represents a set of integer lattice points
28982898
which are M-convex.
@@ -2961,7 +2961,6 @@ def _is_M_convex_(points):
29612961
for p2 in points_set:
29622962
if p2 == p1:
29632963
continue
2964-
delta = list(x2 - x1 for x1, x2 in zip(p1, p2))
29652964
for i in range(dim):
29662965
if p2[i] > p1[i]:
29672966
# modify list_p1 to represent point p1 + e_i - e_j for various i, j

src/sage/rings/polynomial/multi_polynomial_ideal_libsingular.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ cdef ideal *sage_ideal_to_singular_ideal(I) except NULL:
121121
gens = I.gens()
122122
except AttributeError:
123123
gens = I
124-
cdef ideal *result
125124
cdef ring *r
126125
cdef ideal *i
127126
cdef int j = 0
@@ -245,7 +244,6 @@ def slimgb_libsingular(I):
245244
"""
246245
global singular_options
247246

248-
cdef tHomog hom=testHomog
249247
cdef ideal *i
250248
cdef ring *r
251249
cdef ideal *result

src/sage/rings/polynomial/multi_polynomial_libsingular.pyx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,14 +4555,14 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
45554555
(x - y) * (x + y) * (x^2 + y^2) * (x^4 + y^4) * (x^8 + y^8) * (x^16 + y^16) * (x^32 + y^32) * (x^64 + y^64) * (x^128 + y^128) * (x^256 + y^256) * (x^512 + y^512) * (x^1024 + y^1024)
45564556
"""
45574557
cdef ring *_ring = self._parent_ring
4558-
cdef poly *ptemp
45594558
cdef intvec *iv
45604559
cdef int *ivv
45614560
cdef ideal *I = NULL
45624561
cdef MPolynomialRing_libsingular parent = self._parent
45634562
cdef int i
45644563

4565-
if _ring!=currRing: rChangeCurrRing(_ring)
4564+
if _ring != currRing:
4565+
rChangeCurrRing(_ring)
45664566

45674567
if p_IsConstant(self._poly, _ring):
45684568
return self.constant_coefficient().factor()
@@ -4687,14 +4687,13 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
46874687
cdef ideal *_I
46884688
cdef MPolynomialRing_libsingular parent = self._parent
46894689
cdef int i = 0
4690-
cdef int j
46914690
cdef ring *r = self._parent_ring
46924691
cdef ideal *res = NULL
46934692

46944693
if isinstance(I, MPolynomialIdeal):
46954694
I = I.gens()
46964695

4697-
_I = idInit(len(I),1)
4696+
_I = idInit(len(I), 1)
46984697

46994698
for f in I:
47004699
if not (isinstance(f,MPolynomial_libsingular)

src/sage/rings/polynomial/ore_polynomial_element.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ cdef class OrePolynomial(AlgebraElement):
906906
raise TypeError("the base ring must be a field")
907907
cdef OrePolynomial G = self
908908
cdef OrePolynomial U = self._parent.one()
909-
cdef OrePolynomial V, V1, V2, Q, R, T
909+
cdef OrePolynomial V, V1, Q, R, T
910910
cdef Morphism m
911911
if not other:
912912
V = self._parent.zero()
@@ -2568,7 +2568,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial):
25682568
sage: a + a == 2*a
25692569
True
25702570
"""
2571-
cdef Py_ssize_t i, min
2571+
cdef Py_ssize_t i
25722572
cdef list x = (<OrePolynomial_generic_dense>self)._coeffs
25732573
cdef list y = (<OrePolynomial_generic_dense>right)._coeffs
25742574
cdef Py_ssize_t dx = len(x), dy = len(y)
@@ -2599,7 +2599,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial):
25992599
sage: c - c == 0
26002600
True
26012601
"""
2602-
cdef Py_ssize_t i, min
2602+
cdef Py_ssize_t i
26032603
cdef list x = (<OrePolynomial_generic_dense>self)._coeffs
26042604
cdef list y = (<OrePolynomial_generic_dense>right)._coeffs
26052605
cdef Py_ssize_t dx = len(x), dy = len(y)
@@ -2867,16 +2867,16 @@ cdef class OrePolynomial_generic_dense(OrePolynomial):
28672867
sage: a.coefficients(sparse=False)
28682868
[t^2 + 1, 0, t + 1, 0, 1]
28692869
"""
2870-
zero = self.parent().base_ring().zero()
28712870
if sparse:
28722871
return [c for c in self._coeffs if not c.is_zero()]
28732872
else:
28742873
return self._coeffs
28752874

28762875
def hilbert_shift(self, s, var=None):
28772876
r"""
2878-
Return this Ore polynomial with variable shifted by `s`,
2879-
i.e. if this Ore polynomial is `P(x)`, return `P(x+s)`.
2877+
Return this Ore polynomial with variable shifted by `s`.
2878+
2879+
If this Ore polynomial is `P(x)`, this returns `P(x+s)`.
28802880
28812881
INPUT:
28822882

src/sage/rings/polynomial/pbori/pbori.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,6 @@ class BooleanMonomialMonoid(UniqueRepresentation, Monoid_class):
21302130
x*z
21312131
"""
21322132
cdef BooleanMonomial m
2133-
cdef PBMonom t
21342133

21352134
# this is needed for the PolyBoRi python code
21362135
if other is None:

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ cdef class Polynomial(CommutativePolynomial):
21342134
(x^3 + z8^7 + z8^4 + z8^3 + z8^2 + z8, 3)]
21352135
"""
21362136
q = self.base_ring().order() # p^k
2137-
R, x = self.parent().objgen()
2137+
_, x = self.parent().objgen()
21382138

21392139
# Initialise values
21402140
v = self
@@ -2983,7 +2983,6 @@ cdef class Polynomial(CommutativePolynomial):
29832983
# see github issue 24308
29842984
p = -1
29852985
if 0 < p <= right and (self.base_ring() in sage.categories.integral_domains.IntegralDomains() or p.is_prime()):
2986-
x = self.parent().gen()
29872986
ret = self.parent().one()
29882987
e = 1
29892988
q = right
@@ -3782,7 +3781,6 @@ cdef class Polynomial(CommutativePolynomial):
37823781
with a single term.
37833782
"""
37843783
cdef Py_ssize_t d = term.degree()
3785-
cdef Py_ssize_t i
37863784
cdef list coeffs, output
37873785
c = term.get_unsafe(d)
37883786
if term_on_right:
@@ -6471,7 +6469,7 @@ cdef class Polynomial(CommutativePolynomial):
64716469
from sage.rings.qqbar import number_field_elements_from_algebraics
64726470
from sage.schemes.projective.projective_space import ProjectiveSpace
64736471

6474-
K_pre, P, phi = number_field_elements_from_algebraics(self.coefficients())
6472+
K_pre, P, _ = number_field_elements_from_algebraics(self.coefficients())
64756473
Pr = ProjectiveSpace(K_pre, len(P) - 1)
64766474
return Pr.point(P).global_height(prec=prec)
64776475
raise TypeError("Must be over a Numberfield or a Numberfield Order.")
@@ -12306,7 +12304,7 @@ cdef class Polynomial_generic_dense(Polynomial):
1230612304
2*y*x^3 + (y + 3)*x^2 + (-2*y + 1)*x + 1
1230712305
"""
1230812306
cdef Polynomial_generic_dense res
12309-
cdef Py_ssize_t check=0, i, min
12307+
cdef Py_ssize_t i, min
1231012308
x = (<Polynomial_generic_dense>self)._coeffs
1231112309
y = (<Polynomial_generic_dense>right)._coeffs
1231212310
if len(x) > len(y):
@@ -12327,7 +12325,7 @@ cdef class Polynomial_generic_dense(Polynomial):
1232712325

1232812326
cpdef _sub_(self, right):
1232912327
cdef Polynomial_generic_dense res
12330-
cdef Py_ssize_t check=0, i, min
12328+
cdef Py_ssize_t i, min
1233112329
x = (<Polynomial_generic_dense>self)._coeffs
1233212330
y = (<Polynomial_generic_dense>right)._coeffs
1233312331
if len(x) > len(y):

src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ cdef class Polynomial_integer_dense_flint(Polynomial):
402402
cdef RealBall arb_a, arb_z
403403
cdef ComplexBall acb_a, acb_z
404404

405-
cdef unsigned long limbs
406405
cdef fmpz_t a_fmpz
407406
cdef fmpz_t z_fmpz
408407

@@ -1642,16 +1641,15 @@ cdef class Polynomial_integer_dense_flint(Polynomial):
16421641
sage: f = -30*x; f.factor()
16431642
(-1) * 2 * 3 * 5 * x
16441643
"""
1645-
cdef int i
16461644
cdef long deg = fmpz_poly_degree(self._poly)
16471645
# it appears that pari has a window from about degrees 30 and 300
16481646
# in which it beats NTL.
16491647
c = self.content()
1650-
g = self//c
1648+
g = self // c
16511649
if deg < 30 or deg > 300:
1652-
return c.factor()*g._factor_ntl()
1650+
return c.factor() * g._factor_ntl()
16531651
else:
1654-
return c.factor()*g._factor_pari()
1652+
return c.factor() * g._factor_pari()
16551653

16561654
def factor_mod(self, p):
16571655
"""

src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def small_roots(self, X=None, beta=1.0, epsilon=None, **kwds):
629629

630630
f = self.change_ring(ZZ)
631631

632-
P,(x,) = f.parent().objgens()
632+
_, (x,) = f.parent().objgens()
633633

634634
delta = f.degree()
635635

@@ -649,21 +649,21 @@ def small_roots(self, X=None, beta=1.0, epsilon=None, **kwds):
649649

650650
# we could do this much faster, but this is a cheap step
651651
# compared to LLL
652-
g = [x**j * N**(m-i) * f**i for i in range(m) for j in range(delta) ]
653-
g.extend([x**i * f**m for i in range(t)]) # h
652+
g = [x**j * N**(m-i) * f**i for i in range(m) for j in range(delta)]
653+
g.extend([x**i * f**m for i in range(t)]) # h
654654

655655
B = Matrix(ZZ, len(g), delta*m + max(delta,t) )
656656
for i in range(B.nrows()):
657657
for j in range( g[i].degree()+1 ):
658-
B[i,j] = g[i][j]*X**j
658+
B[i, j] = g[i][j]*X**j
659659

660660
B = B.LLL(**kwds)
661661

662-
f = sum([ZZ(B[0,i]//X**i)*x**i for i in range(B.ncols())])
662+
f = sum([ZZ(B[0, i]//X**i)*x**i for i in range(B.ncols())])
663663
R = f.roots()
664664

665665
ZmodN = self.base_ring()
666-
roots = set([ZmodN(r) for r,m in R if abs(r) <= X])
666+
roots = set(ZmodN(r) for r, m in R if abs(r) <= X)
667667
Nbeta = N**beta
668668
return [root for root in roots if N.gcd(ZZ(self(root))) >= Nbeta]
669669

src/sage/rings/polynomial/polynomial_zmod_flint.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
190190
"""
191191
cdef list l_in = x
192192
cdef unsigned long length = len(l_in)
193-
cdef unsigned long modulus = nmod_poly_modulus(&self.x)
194193
cdef int i
195194
if length == 0:
196195
nmod_poly_zero(&self.x)

0 commit comments

Comments
 (0)