Skip to content

Commit a8f16cf

Browse files
author
Release Manager
committed
gh-39575: full cython-lint cleanup in data_structure pyx files This fixes most of the warning issued by `cython-lint` on this directory. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #39575 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 1b95945 + 49a0528 commit a8f16cf

File tree

8 files changed

+52
-52
lines changed

8 files changed

+52
-52
lines changed

src/sage/data_structures/binary_matrix.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ cdef inline void binary_matrix_fill(binary_matrix_t m, bint bit) noexcept:
8686
"""
8787
cdef mp_bitcnt_t i
8888

89-
if bit: # set the matrix to 1
89+
if bit: # set the matrix to 1
9090
for i in range(m.n_rows):
9191
bitset_set_first_n(m.rows[i], m.n_cols)
9292
else:
@@ -117,7 +117,7 @@ cdef inline void binary_matrix_set(binary_matrix_t m, mp_bitcnt_t row, mp_bitcnt
117117
r"""
118118
Set an entry
119119
"""
120-
bitset_set_to(m.rows[row],col,value)
120+
bitset_set_to(m.rows[row], col, value)
121121

122122
cdef inline bint binary_matrix_get(binary_matrix_t m, mp_bitcnt_t row, mp_bitcnt_t col) noexcept:
123123
r"""
@@ -129,7 +129,7 @@ cdef inline binary_matrix_print(binary_matrix_t m):
129129
r"""
130130
Print the binary matrix
131131
"""
132-
cdef mp_bitcnt_t i,j
132+
cdef mp_bitcnt_t i, j
133133
import sys
134134
for i in range(m.n_rows):
135135
for j in range(m.n_cols):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
cdef Py_ssize_t binary_search(Py_ssize_t* v, Py_ssize_t n, Py_ssize_t x, Py_ssize_t* ins) noexcept
2-
cdef Py_ssize_t binary_search0(Py_ssize_t* v, Py_ssize_t n, Py_ssize_t x) noexcept
2+
cdef Py_ssize_t binary_search0(Py_ssize_t* v, Py_ssize_t n, Py_ssize_t x) noexcept

src/sage/data_structures/bitset.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#*****************************************************************************
1+
# ***************************************************************************
22
# Copyright (C) 2008 Robert Bradshaw <[email protected]>
33
#
44
# Distributed under the terms of the GNU General Public License (GPL)
55
# as published by the Free Software Foundation; either version 2 of
66
# the License, or (at your option) any later version.
7-
# http://www.gnu.org/licenses/
8-
#*****************************************************************************
7+
# https://www.gnu.org/licenses/
8+
# ***************************************************************************
99

1010
from sage.data_structures.bitset_base cimport bitset_t
1111

src/sage/data_structures/bitset.pyx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ linear in ``capacity``.
1616
faster.
1717
"""
1818

19-
#*****************************************************************************
19+
# ****************************************************************************
2020
# Copyright (C) 2009 Jason Grout <[email protected]>
2121
#
2222
# Distributed under the terms of the GNU General Public License (GPL)
@@ -28,8 +28,8 @@ linear in ``capacity``.
2828
#
2929
# The full text of the GPL is available at:
3030
#
31-
# http://www.gnu.org/licenses/
32-
#*****************************************************************************
31+
# https://www.gnu.org/licenses/
32+
# ****************************************************************************
3333

3434
from sage.data_structures.bitset_base cimport *
3535
from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
@@ -763,7 +763,6 @@ cdef class FrozenBitset:
763763
...
764764
ValueError: other cannot be None
765765
"""
766-
cdef bint retval
767766
if other is None:
768767
raise ValueError("other cannot be None")
769768
cdef FrozenBitset left, right
@@ -778,7 +777,7 @@ cdef class FrozenBitset:
778777
# Assumes ``left.size <= right.size``.
779778
return bitset_are_disjoint(left._bitset, right._bitset)
780779

781-
def __contains__(self, unsigned long n):
780+
def __contains__(self, unsigned long n) -> bool:
782781
"""
783782
Test to see if ``n`` is in ``self``.
784783

@@ -821,7 +820,7 @@ cdef class FrozenBitset:
821820
"""
822821
return bitset_len(self._bitset)
823822
824-
def __str__(self):
823+
def __str__(self) -> str:
825824
"""
826825
Return a string representing the bitset as a binary vector.
827826

@@ -2271,7 +2270,6 @@ def test_bitset_set_first_n(py_a, long n):
22712270
sage: test_bitset_set_first_n('00'*64, 128)
22722271
a.set_first_n(n) 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
22732272
"""
2274-
cdef bint bit = True
22752273
cdef bitset_t a
22762274
22772275
bitset_from_str(a, py_a)

src/sage/data_structures/bitset_base.pxd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ AUTHORS:
1818
the size of the given bitsets (:issue:`15820`)
1919
"""
2020

21-
#*****************************************************************************
21+
# ***************************************************************************
2222
# Copyright (C) 2008 Robert Bradshaw <[email protected]>
2323
#
2424
# Distributed under the terms of the GNU General Public License (GPL)
2525
# as published by the Free Software Foundation; either version 2 of
2626
# the License, or (at your option) any later version.
27-
# http://www.gnu.org/licenses/
28-
#*****************************************************************************
27+
# https://www.gnu.org/licenses/
28+
# ***************************************************************************
2929

3030
# This file declares the bitset types and the (inline functions).
3131
# Few functions that are not inline are in the `pyx` file.
@@ -324,7 +324,7 @@ cdef inline bint mpn_equal_bits_shifted(mp_srcptr b1, mp_srcptr b2, mp_bitcnt_t
324324

325325
cdef mp_limb_t b1h = b1[nlimbs]
326326
tmp_limb = (b2[i2] >> bit_offset)
327-
if (n%GMP_LIMB_BITS)+bit_offset > GMP_LIMB_BITS:
327+
if (n % GMP_LIMB_BITS) + bit_offset > GMP_LIMB_BITS:
328328
# Need bits from the next limb of b2
329329
tmp_limb |= (b2[preinc(i2)] << neg_bit_offset)
330330
return (b1h ^ tmp_limb) & mask == 0

src/sage/data_structures/bitset_base.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Few functions from ``bitset_base.pxd`` that are not inlined.
33
"""
44

5-
#*****************************************************************************
5+
# ***************************************************************************
66
# Copyright (C) 2008 Robert Bradshaw <[email protected]>
77
#
88
# Distributed under the terms of the GNU General Public License (GPL)
99
# as published by the Free Software Foundation; either version 2 of
1010
# the License, or (at your option) any later version.
11-
# http://www.gnu.org/licenses/
12-
#*****************************************************************************
11+
# https://www.gnu.org/licenses/
12+
# ***************************************************************************
1313

1414
cdef char* bitset_chars(char* s, fused_bitset_t bits, char zero=c'0', char one=c'1') noexcept:
1515
"""

src/sage/data_structures/blas_dict.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ nonzero (as tested with `bool(v)`).
2323
2424
This is mostly used by :class:`CombinatorialFreeModule`.
2525
"""
26-
#*****************************************************************************
26+
# ***************************************************************************
2727
# Copyright (C) 2010 Christian Stump <[email protected]>
2828
# 2016 Travis Scrimshaw <[email protected]>
2929
# 2016 Nicolas M. Thiéry <nthiery at users.sf.net>
@@ -32,8 +32,8 @@ This is mostly used by :class:`CombinatorialFreeModule`.
3232
# it under the terms of the GNU General Public License as published by
3333
# the Free Software Foundation, either version 2 of the License, or
3434
# (at your option) any later version.
35-
# http://www.gnu.org/licenses/
36-
#*****************************************************************************
35+
# https://www.gnu.org/licenses/
36+
# ***************************************************************************
3737

3838
cpdef int iaxpy(a, dict X, dict Y, bint remove_zeros=True, bint factor_on_left=True) except -1:
3939
r"""
@@ -112,13 +112,13 @@ cpdef int iaxpy(a, dict X, dict Y, bint remove_zeros=True, bint factor_on_left=T
112112
flag = -1
113113
elif not a:
114114
return 0
115-
for (key, value) in X.iteritems():
115+
for key, value in X.items():
116116
if flag == -1:
117117
if key in Y:
118-
Y[key] -= value
118+
Y[key] -= value
119119
else:
120-
Y[key] = -value
121-
continue # no need to check for zero
120+
Y[key] = -value
121+
continue # no need to check for zero
122122
else:
123123
if flag != 1:
124124
# If we had the guarantee that `a` is in the base
@@ -136,8 +136,8 @@ cpdef int iaxpy(a, dict X, dict Y, bint remove_zeros=True, bint factor_on_left=T
136136
if key in Y:
137137
Y[key] += value
138138
else:
139-
Y[key] = value
140-
continue # no need to check for zero
139+
Y[key] = value
140+
continue # no need to check for zero
141141
if remove_zeros and not Y[key]:
142142
del Y[key]
143143
return 0
@@ -217,7 +217,7 @@ cpdef dict negate(dict D):
217217
sage: blas.negate(D1)
218218
{0: -1, 1: -1}
219219
"""
220-
return { key: -value for key, value in D.iteritems() }
220+
return {key: -value for key, value in D.items()}
221221

222222
cpdef dict scal(a, dict D, bint factor_on_left=True):
223223
r"""
@@ -345,7 +345,7 @@ cpdef dict linear_combination(dict_factor_iter, bint factor_on_left=True):
345345
cdef dict D
346346

347347
for D, a in dict_factor_iter:
348-
if not a: # We multiply by 0, so nothing to do
348+
if not a: # We multiply by 0, so nothing to do
349349
continue
350350
if not result and a == 1:
351351
result = D.copy()

src/sage/data_structures/bounded_integer_sequences.pyx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ cdef bint biseq_init_list(biseq_t R, list data, size_t bound) except -1:
195195
sig_check()
196196
item_c = item
197197
if item_c > bound:
198-
raise OverflowError("list item {!r} larger than {}".format(item, bound) )
198+
raise OverflowError("list item {!r} larger than {}".format(item, bound))
199199
biseq_inititem(R, index, item_c)
200200
index += 1
201201

@@ -389,7 +389,8 @@ cdef mp_size_t biseq_contains(biseq_t S1, biseq_t S2, mp_size_t start) except -2
389389
sig_on()
390390
for index from start <= index <= S1.length-S2.length:
391391
if mpn_equal_bits_shifted(S2.data.bits, S1.data.bits,
392-
S2.length*S2.itembitsize, index*S2.itembitsize):
392+
S2.length * S2.itembitsize,
393+
index * S2.itembitsize):
393394
sig_off()
394395
return index
395396
sig_off()
@@ -424,7 +425,8 @@ cdef mp_size_t biseq_startswith_tail(biseq_t S1, biseq_t S2, mp_size_t start) ex
424425
sig_on()
425426
for index from start <= index < S2.length:
426427
if mpn_equal_bits_shifted(S1.data.bits, S2.data.bits,
427-
(S2.length - index)*S2.itembitsize, index*S2.itembitsize):
428+
(S2.length - index) * S2.itembitsize,
429+
index * S2.itembitsize):
428430
sig_off()
429431
return index
430432
sig_off()
@@ -1381,35 +1383,35 @@ def _biseq_stresstest():
13811383
cdef list L = [BoundedIntegerSequence(6, [randint(0, 5) for z in range(randint(4, 10))]) for y in range(100)]
13821384
cdef BoundedIntegerSequence S, T
13831385
while True:
1384-
branch = randint(0,4)
1386+
branch = randint(0, 4)
13851387
if branch == 0:
1386-
L[randint(0,99)] = L[randint(0,99)]+L[randint(0,99)]
1388+
L[randint(0, 99)] = L[randint(0, 99)] + L[randint(0, 99)]
13871389
elif branch == 1:
1388-
x = randint(0,99)
1390+
x = randint(0, 99)
13891391
if len(L[x]):
1390-
y = randint(0,len(L[x])-1)
1391-
z = randint(y,len(L[x])-1)
1392-
L[randint(0,99)] = L[x][y:z]
1392+
y = randint(0, len(L[x]) - 1)
1393+
z = randint(y, len(L[x]) - 1)
1394+
L[randint(0, 99)] = L[x][y:z]
13931395
else:
1394-
L[x] = BoundedIntegerSequence(6, [randint(0,5) for z in range(randint(4,10))])
1396+
L[x] = BoundedIntegerSequence(6, [randint(0, 5) for z in range(randint(4, 10))])
13951397
elif branch == 2:
1396-
t = list(L[randint(0,99)])
1397-
t = repr(L[randint(0,99)])
1398-
t = L[randint(0,99)].list()
1398+
t = list(L[randint(0, 99)])
1399+
t = repr(L[randint(0, 99)])
1400+
t = L[randint(0, 99)].list()
13991401
elif branch == 3:
1400-
x = randint(0,99)
1402+
x = randint(0, 99)
14011403
if len(L[x]):
1402-
y = randint(0,len(L[x])-1)
1404+
y = randint(0, len(L[x])-1)
14031405
t = L[x][y]
14041406
try:
14051407
t = L[x].index(t)
14061408
except ValueError:
1407-
raise ValueError("{} should be in {} (bound {}) at position {}".format(t,L[x],L[x].bound(),y))
1409+
raise ValueError("{} should be in {} (bound {}) at position {}".format(t, L[x], L[x].bound(), y))
14081410
else:
1409-
L[x] = BoundedIntegerSequence(6, [randint(0,5) for z in range(randint(4,10))])
1411+
L[x] = BoundedIntegerSequence(6, [randint(0, 5) for z in range(randint(4, 10))])
14101412
elif branch == 4:
1411-
S = L[randint(0,99)]
1412-
T = L[randint(0,99)]
1413-
biseq_startswith(S.data,T.data)
1413+
S = L[randint(0, 99)]
1414+
T = L[randint(0, 99)]
1415+
biseq_startswith(S.data, T.data)
14141416
biseq_contains(S.data, T.data, 0)
14151417
biseq_startswith_tail(S.data, T.data, 0)

0 commit comments

Comments
 (0)