Skip to content

Commit 7d56342

Browse files
author
Release Manager
committed
sagemathgh-40996: Iteritems no longer get rid of all "iteritems" and "itervalues" remaining in cython code ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: sagemath#40996 Reported by: Frédéric Chapoton Reviewer(s): Lorenz Panny
2 parents 86acefb + e22a2a0 commit 7d56342

33 files changed

+80
-115
lines changed

src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ cpdef find_brouwer_separable_design(int k, int n):
799799
from sage.combinat.designs.database import QDM as __QDM
800800
cdef dict _QDM = __QDM
801801
cdef dict ioa_indexed_by_n_minus_x = {}
802-
for x in _QDM.itervalues():
802+
for x in _QDM.values():
803803
for (n, _, _, u), (k, _) in x.items():
804804
if u > 1:
805805
if n not in ioa_indexed_by_n_minus_x:

src/sage/graphs/base/boost_graph.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ cdef boost_clustering_coeff(BoostGenGraph *g, vertices):
273273
result_d = g[0].clustering_coeff(vi)
274274
sig_off()
275275
clust_of_v[v] = result_d
276-
return ((sum(clust_of_v.itervalues()) / len(clust_of_v)), clust_of_v)
276+
return ((sum(clust_of_v.values()) / len(clust_of_v)), clust_of_v)
277277

278278

279279
cpdef clustering_coeff(g, vertices=None):

src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ def get_orbits(list gens, int n):
10541054
OP_dealloc(OP)
10551055
sig_free(perm_ints)
10561056

1057-
return list(orbit_dict.itervalues())
1057+
return list(orbit_dict.values())
10581058

10591059

10601060
# Canonical augmentation

src/sage/libs/gap/element.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ cdef Obj make_gap_record(sage_dict) except NULL:
193193
sage: libgap({'a': 1, 'b':123}) # indirect doctest
194194
rec( a := 1, b := 123 )
195195
"""
196-
data = [ (str(key), libgap(value)) for key, value in sage_dict.iteritems() ]
197-
196+
cdef list data
198197
cdef Obj rec
199198
cdef GapElement val
200199
cdef UInt rnam
201200

201+
data = [(str(key), libgap(value)) for key, value in sage_dict.items()]
202+
202203
try:
203204
GAP_Enter()
204205
rec = GAP_NewPrecord(len(data))

src/sage/libs/singular/option.pyx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ cdef class LibSingularOptions_abstract:
166166
sage: opt['degBound']
167167
2
168168
"""
169-
for k,v in kwds.iteritems():
169+
for k, v in kwds.items():
170170
self[k] = v
171171

172172
def __getitem__(self, name):
@@ -615,7 +615,7 @@ cdef class LibSingularOptionsContext:
615615
self.bck_degBound.append(Kstd1_deg)
616616
self.bck_multBound.append(Kstd1_mu)
617617
opt = self.opt.__class__()
618-
for k,v in self.options.iteritems():
618+
for k, v in self.options.items():
619619
opt[k] = v
620620

621621
def __call__(self, **kwds):
@@ -631,8 +631,7 @@ cdef class LibSingularOptionsContext:
631631
....: opt['redTail']
632632
False
633633
"""
634-
new = self.__class__(self.opt, **kwds)
635-
return new
634+
return self.__class__(self.opt, **kwds)
636635

637636
def __exit__(self, typ, value, tb):
638637
"""

src/sage/matrix/matrix2.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,7 @@ cdef class Matrix(Matrix1):
30183018
return self.dense_matrix()
30193019

30203020
if self.is_sparse():
3021-
values = {ij: phi(v) for ij, v in self.dict().iteritems()}
3021+
values = {ij: phi(v) for ij, v in self.dict().items()}
30223022
if R is None:
30233023
R = sage.structure.sequence.Sequence(values.values()).universe()
30243024
else:

src/sage/matrix/matrix_sparse.pyx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ cdef class Matrix_sparse(matrix.Matrix):
156156

157157
cdef long h = 0, k, l
158158
cdef Py_ssize_t i, j
159-
for ij, x in D.iteritems():
159+
for ij, x in D.items():
160160
sig_check()
161161
i = (<tuple>ij)[0]
162162
j = (<tuple>ij)[1]
@@ -362,7 +362,7 @@ cdef class Matrix_sparse(matrix.Matrix):
362362
def _unpickle_generic(self, data, int version):
363363
cdef Py_ssize_t i, j
364364
if version == -1:
365-
for (i, j), x in data.iteritems():
365+
for (i, j), x in data.items():
366366
self.set_unsafe(i, j, x)
367367
else:
368368
raise RuntimeError("unknown matrix version (=%s)" % version)
@@ -643,7 +643,7 @@ cdef class Matrix_sparse(matrix.Matrix):
643643
R = phi.codomain()
644644
M = sage.matrix.matrix_space.MatrixSpace(R, self._nrows,
645645
self._ncols, sparse=True)
646-
return M({ij: phi(z) for ij, z in self.dict().iteritems()})
646+
return M({ij: phi(z) for ij, z in self.dict().items()})
647647

648648
def apply_map(self, phi, R=None, sparse=True):
649649
r"""
@@ -768,7 +768,7 @@ cdef class Matrix_sparse(matrix.Matrix):
768768
zero_res = phi(self.base_ring()(0))
769769
else:
770770
zero_res = None
771-
v = [(ij, phi(z)) for ij,z in self_dict.iteritems()]
771+
v = [(ij, phi(z)) for ij,z in self_dict.items()]
772772
if R is None:
773773
w = [x for _, x in v]
774774
if zero_res is not None:
@@ -826,7 +826,8 @@ cdef class Matrix_sparse(matrix.Matrix):
826826

827827
if self._nrows==0 or self._ncols==0:
828828
return self.__copy__()
829-
v = [(ij, sage.calculus.functional.derivative(z, var)) for ij, z in self.dict().iteritems()]
829+
v = [(ij, sage.calculus.functional.derivative(z, var))
830+
for ij, z in self.dict().items()]
830831
if R is None:
831832
w = [x for _, x in v]
832833
w = sage.structure.sequence.Sequence(w)
@@ -1154,7 +1155,7 @@ cdef class Matrix_sparse(matrix.Matrix):
11541155
raise ArithmeticError("number of rows of matrix must equal degree of vector")
11551156
parent = self.row_ambient_module(base_ring=None, sparse=v.is_sparse_c())
11561157
s = parent.zero_vector()
1157-
for (i, j), a in self._dict().iteritems():
1158+
for (i, j), a in self._dict().items():
11581159
s[j] += v[i] * a
11591160
return s
11601161

@@ -1207,7 +1208,7 @@ cdef class Matrix_sparse(matrix.Matrix):
12071208
raise ArithmeticError("number of columns of matrix must equal degree of vector")
12081209
parent = self.column_ambient_module(base_ring=None, sparse=v.is_sparse_c())
12091210
s = parent.zero_vector()
1210-
for (i, j), a in self._dict().iteritems():
1211+
for (i, j), a in self._dict().items():
12111212
s[i] += a * v[j]
12121213
return s
12131214

src/sage/matrix/matrix_symbolic_dense.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ cdef class Matrix_symbolic_dense(Matrix_generic_dense):
977977

978978
if args:
979979
if len(args) == 1 and isinstance(args[0], dict):
980-
kwargs = {repr(x): vx for x, vx in args[0].iteritems()}
980+
kwargs = {repr(x): vx for x, vx in args[0].items()}
981981
else:
982982
raise ValueError('use named arguments, like EXPR(x=..., y=...)')
983983

src/sage/matrix/matrix_symbolic_sparse.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ cdef class Matrix_symbolic_sparse(Matrix_generic_sparse):
985985

986986
if args:
987987
if len(args) == 1 and isinstance(args[0], dict):
988-
kwargs = {repr(x): vx for x, vx in args[0].iteritems()}
988+
kwargs = {repr(x): vx for x, vx in args[0].items()}
989989
else:
990990
raise ValueError('use named arguments, like EXPR(x=..., y=...)')
991991

src/sage/matroids/linear_matroid.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,14 +2200,14 @@ cdef class LinearMatroid(BasisExchangeMatroid):
22002200
while todo:
22012201
r = todo.pop()
22022202
cocirc = self.fundamental_cocycle(B, r)
2203-
for s, v in cocirc.iteritems():
2203+
for s, v in cocirc.items():
22042204
if s != r and s not in mult2:
22052205
mult2[s] = mult[r] * v
22062206
todo2.add(s)
22072207
while todo2:
22082208
s = todo2.pop()
22092209
circ = self.fundamental_cycle(B, s)
2210-
for t, w in circ.iteritems():
2210+
for t, w in circ.items():
22112211
if t != s and t not in mult:
22122212
mult[t] = mult2[s] / w
22132213
if t not in T:
@@ -2398,7 +2398,7 @@ cdef class LinearMatroid(BasisExchangeMatroid):
23982398
parallel = True
23992399
e = min(p)
24002400
ratio = c[e] / p[e]
2401-
for f, w in p.iteritems():
2401+
for f, w in p.items():
24022402
if c[f] / w != ratio:
24032403
parallel = False
24042404
break

0 commit comments

Comments
 (0)