Skip to content

Commit

Permalink
Trac #29103: get rid of part of itervalues
Browse files Browse the repository at this point in the history
after #29077

There are much more cases, so only half of them is taken care of.

URL: https://trac.sagemath.org/29103
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Feb 9, 2020
2 parents 554fa02 + cbb20e6 commit af348cf
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 56 deletions.
5 changes: 2 additions & 3 deletions src/sage/categories/crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
# it under the terms of the GNU General Public License 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 __future__ import print_function
from builtins import zip
from six import itervalues

from sage.misc.cachefunc import cached_method
from sage.misc.abstract_method import abstract_method
Expand Down Expand Up @@ -789,7 +788,7 @@ def crystal_morphism(self, on_gens, codomain=None,
codomain = on_gens[0].parent()
elif isinstance(on_gens, dict):
if on_gens:
codomain = next(itervalues(on_gens)).parent()
codomain = next(iter(on_gens.values())).parent()
else:
for x in self.module_generators:
y = on_gens(x)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/alternating_sign_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# ****************************************************************************
from __future__ import division
from six.moves import range, zip
from six import itervalues, add_metaclass
from six import add_metaclass

import copy
from sage.misc.classcall_metaclass import ClasscallMetaclass
Expand Down Expand Up @@ -1495,7 +1495,7 @@ def _lattice_initializer(self):
"""
mts, rels = MonotoneTriangles(self._n)._lattice_initializer()
bij = {t: self.from_monotone_triangle(t) for t in mts}
return (itervalues(bij), [(bij[a], bij[b]) for (a, b) in rels])
return (bij.values(), [(bij[a], bij[b]) for (a, b) in rels])

def cover_relations(self):
r"""
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,7 @@ def _process_filling_and_shape(self, filling, shape):
"""
if isinstance(filling, dict):
try:
from six import itervalues
v = next(itervalues(filling))
v = next(iter(filling.values()))
if isinstance(v, dict):
# it is a dict of dicts
F = dict()
Expand Down
17 changes: 6 additions & 11 deletions src/sage/combinat/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,13 @@
# it under the terms of the GNU General Public License 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 __future__ import print_function, absolute_import

from builtins import zip
from six.moves import range

from six import itervalues

from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
Expand All @@ -248,7 +246,7 @@
from sage.structure.global_options import GlobalOptions
from sage.interfaces.all import gap
from sage.rings.all import ZZ, Integer, PolynomialRing
from sage.arith.all import factorial
from sage.arith.all import factorial, multinomial
from sage.matrix.matrix_space import MatrixSpace
from sage.combinat.tools import transitive_ideal
from sage.combinat.composition import Composition
Expand Down Expand Up @@ -5507,8 +5505,8 @@ def cardinality(self):
sage: Permutations(3,4).cardinality()
0
"""
if self._k <= self.n and self._k >= 0:
return factorial(self.n) // factorial(self.n-self._k)
if 0 <= self._k <= self.n:
return factorial(self.n) // factorial(self.n - self._k)
return ZZ.zero()

def random_element(self):
Expand Down Expand Up @@ -5684,11 +5682,8 @@ def cardinality(self):
for i in mset_list:
d[i] = d.get(i, 0) + 1

c = factorial(len(lmset))
for i in itervalues(d):
if i != 1:
c //= factorial(i)
return ZZ(c)
return ZZ(multinomial(d.values()))


class Permutations_set(Permutations):
"""
Expand Down
20 changes: 10 additions & 10 deletions src/sage/combinat/words/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
# ****************************************************************************
from __future__ import print_function

import six
from six.moves import range
import itertools

Expand Down Expand Up @@ -393,7 +392,7 @@ def __init__(self, data, domain=None, codomain=None):
self._morph = {}

dom_alph = list()
for (key,val) in six.iteritems(data):
for key, val in data.items():
dom_alph.append(key)
if val in codomain.alphabet():
self._morph[key] = codomain([val])
Expand Down Expand Up @@ -474,7 +473,7 @@ def _build_codomain(self, data):
Finite words over {0, 1, 2}
"""
codom_alphabet = set()
for key,val in six.iteritems(data):
for key, val in data.items():
try:
it = iter(val)
except Exception:
Expand All @@ -490,7 +489,7 @@ def __hash__(self):
sage: hash(WordMorphism('a->ab,b->ba')) # random
7211091143079804375
"""
return hash(tuple((k,v) for k,v in six.iteritems(self._morph))) ^ hash(self._codomain)
return hash(tuple((k,v) for k,v in self._morph.items())) ^ hash(self._codomain)

def __eq__(self, other):
r"""
Expand Down Expand Up @@ -603,7 +602,8 @@ def __str__(self):
sage: str(s)
'a->ab, b->ba'
"""
L = [str(lettre) + '->' + image.string_rep() for lettre,image in six.iteritems(self._morph)]
L = [str(lettre) + '->' + image.string_rep()
for lettre, image in self._morph.items()]
return ', '.join(sorted(L))

def __call__(self, w, order=1, datatype=None):
Expand Down Expand Up @@ -977,7 +977,7 @@ def __mul__(self, other):
sage: m * WordMorphism('')
WordMorphism:
"""
return WordMorphism(dict((key, self(w)) for (key, w) in six.iteritems(other._morph)), codomain=self.codomain())
return WordMorphism(dict((key, self(w)) for key, w in other._morph.items()), codomain=self.codomain())

def __pow__(self, exp):
r"""
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def extend_by(self, other):
raise TypeError("other (=%s) is not a WordMorphism"%other)

nv = dict(other._morph)
for k,v in six.iteritems(self._morph):
for k, v in self._morph.items():
nv[k] = v
return WordMorphism(nv)

Expand Down Expand Up @@ -1290,7 +1290,7 @@ def images(self):
sage: sorted(WordMorphism('6->ab,y->5,0->asd').images())
[word: 5, word: ab, word: asd]
"""
return list(six.itervalues(self._morph))
return list(self._morph.values())

def reversal(self):
r"""
Expand All @@ -1303,7 +1303,7 @@ def reversal(self):
sage: WordMorphism('a->ab,b->a').reversal()
WordMorphism: a->ba, b->a
"""
return WordMorphism(dict((key, w.reversal()) for (key, w) in six.iteritems(self._morph)),codomain=self._codomain)
return WordMorphism(dict((key, w.reversal()) for (key, w) in self._morph.items()),codomain=self._codomain)

def is_empty(self):
r"""
Expand Down Expand Up @@ -2186,7 +2186,7 @@ def conjugate(self, pos):
sage: m.conjugate(2)
WordMorphism: a->cdeab, b->zxy
"""
return WordMorphism(dict((key, w.conjugate(pos)) for (key, w) in six.iteritems(self._morph)))
return WordMorphism(dict((key, w.conjugate(pos)) for (key, w) in self._morph.items()))

def has_left_conjugate(self):
r"""
Expand Down
6 changes: 2 additions & 4 deletions src/sage/data_structures/mutable_poset.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@
# ****************************************************************************
from __future__ import print_function

from six import itervalues

from sage.structure.sage_object import SageObject


Expand Down Expand Up @@ -1690,7 +1688,7 @@ def _copy_shells_(self, other, mapping):
self._null_ = other._null_._copy_all_linked_(memo, self, mapping)
self._oo_ = memo[id(other._oo_)]
self._shells_ = {f.key: f for f in iter(memo[id(e)] for e in
itervalues(other._shells_))}
other._shells_.values())}

def copy(self, mapping=None):
r"""
Expand Down Expand Up @@ -1771,7 +1769,7 @@ def shells(self, include_special=False):
"""
if include_special:
yield self.null
for e in itervalues(self._shells_):
for e in self._shells_.values():
yield e
if include_special:
yield self.oo
Expand Down
4 changes: 2 additions & 2 deletions src/sage/databases/conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from six import itervalues, iteritems
from six import iteritems
from six.moves import cPickle as pickle

import collections
Expand Down Expand Up @@ -168,7 +168,7 @@ def __len__(self):
return self._len
except AttributeError:
pass
self._len = sum(len(a) for a in itervalues(self._store))
self._len = sum(len(a) for a in self._store.values())
return self._len

def __iter__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6975,7 +6975,7 @@ def cores(self, k=None, with_labels=False):
if with_labels:
return core
else:
return list(six.itervalues(core))
return list(core.values())

@doc_index("Leftovers")
def modular_decomposition(self, algorithm='habib'):
Expand Down
3 changes: 1 addition & 2 deletions src/sage/knots/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
# ****************************************************************************
from __future__ import division

import six
from six.moves import range

from sage.matrix.constructor import matrix
Expand Down Expand Up @@ -1340,7 +1339,7 @@ def pd_code(self):
else:
crossing_dic = {}

pd = list(six.itervalues(crossing_dic))
pd = list(crossing_dic.values())
self._pd_code = pd
return self._pd_code

Expand Down
6 changes: 2 additions & 4 deletions src/sage/matroids/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@
# 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 __future__ import absolute_import

from six import itervalues

from itertools import combinations
from sage.matrix.constructor import Matrix
from sage.graphs.all import Graph
Expand Down Expand Up @@ -917,7 +915,7 @@ def revlex_sort_key(s):

if groundset is None:
groundset = set()
for X in itervalues(CC):
for X in CC.values():
for Y in X:
groundset.update(Y)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/sage_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@

from __future__ import print_function, absolute_import

from six import itervalues, iteritems, integer_types, string_types
from six import iteritems, integer_types, string_types


def sage_input(x, preparse=True, verify=False, allow_locals=False):
Expand Down Expand Up @@ -1915,7 +1915,7 @@ def _sie_referenced(self):
"""
refs = self._sie_args[:]
refs.append(self._sie_func)
refs.extend(itervalues(self._sie_kwargs))
refs.extend(self._sie_kwargs.values())
return refs

def _sie_format(self, sif):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/pollack_stevens/manin_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function, absolute_import
from six import itervalues, iteritems
from six import iteritems
from six.moves import range

from sage.rings.continued_fraction import convergents
Expand Down Expand Up @@ -712,7 +712,7 @@ def normalize(self):
(1 + O(11^2), 2 + O(11))
"""
sd = self._dict
for val in itervalues(sd):
for val in sd.values():
val.normalize()
return self

Expand Down
6 changes: 3 additions & 3 deletions src/sage/modules/multi_filtered_vector_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from six import iteritems, itervalues
from six import iteritems

from sage.rings.all import QQ, ZZ, Integer
from sage.rings.infinity import infinity, minus_infinity
Expand Down Expand Up @@ -84,11 +84,11 @@ def MultiFilteredVectorSpace(arg, base_ring=None, check=True):
base_ring = QQ
else:
filtration = dict(arg)
F = next(itervalues(arg)) # the first filtration
F = next(iter(arg.values())) # the first filtration
dim = F.dimension()
if base_ring is None:
base_ring = F.base_ring()
for deg in filtration.keys():
for deg in filtration:
filt = filtration[deg]
if filt.base_ring() != base_ring:
filt = filt.change_ring(base_ring)
Expand Down
9 changes: 4 additions & 5 deletions src/sage/schemes/elliptic_curves/ell_curve_isogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import print_function, absolute_import
from six import itervalues
from six.moves import range

from copy import copy
Expand Down Expand Up @@ -2087,12 +2086,12 @@ def __compute_via_velu(self, xP, yP):
a3 = self.__E1.a3()

# next iterate over the 2torsion points of the kernel
for Qvalues in itervalues(ker_2tor):
for Qvalues in ker_2tor.values():
(tX, tY) = self.__velu_sum_helper(Qvalues, a1, a3, xP, yP)
X = X + tX
Y = Y + tY

for Qvalues in itervalues(ker_non2tor):
for Qvalues in ker_non2tor.values():
(tX, tY) = self.__velu_sum_helper(Qvalues, a1, a3, xP, yP)
X = X + tX
Y = Y + tY
Expand Down Expand Up @@ -2158,11 +2157,11 @@ def __init_kernel_polynomial_velu(self):

psi = poly_ring(1)

for Qvalues in itervalues(self.__kernel_2tor):
for Qvalues in self.__kernel_2tor.values():
xQ = invX(x=Qvalues[0])
psi = psi*(x - xQ)

for Qvalues in itervalues(self.__kernel_non2tor):
for Qvalues in self.__kernel_non2tor.values():
xQ = invX(x=Qvalues[0])
psi = psi*(x - xQ)

Expand Down
Loading

0 comments on commit af348cf

Please sign in to comment.