Skip to content

Commit

Permalink
Trac #33956: some better .join with iterator inside
Browse files Browse the repository at this point in the history
URL: https://trac.sagemath.org/33956
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Jun 12, 2022
2 parents a33f2df + aa7d2e4 commit b3d6a0b
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/sage/databases/findstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4597,8 +4597,8 @@ def name(self, style="singular"):
"DecoratedPermutations":
_SupportedFindStatCollection(lambda x: DecoratedPermutation([v if v > 0 else (i if v == 0 else -i)
for i, v in enumerate(literal_eval(x.replace("+","0").replace("-","-1")), 1)]),
lambda x: "[" + ",".join([str(v) if abs(v) != i else ("+" if v > 0 else "-")
for i, v in enumerate(x, 1)]) + "]",
lambda x: "[" + ",".join((str(v) if abs(v) != i else ("+" if v > 0 else "-")
for i, v in enumerate(x, 1))) + "]",
DecoratedPermutations,
lambda x: x.size(),
lambda x: isinstance(x, DecoratedPermutation)),
Expand Down
5 changes: 3 additions & 2 deletions src/sage/doctest/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,11 @@ def parse_docstring(self, docstring, namespace, start):
PythonStringSource = dynamic_class("sage.doctest.sources.PythonStringSource",
(StringDocTestSource, PythonSource))
min_indent = self.parser._min_indent(docstring)
pysource = '\n'.join([l[min_indent:] for l in docstring.split('\n')])
pysource = '\n'.join(l[min_indent:] for l in docstring.split('\n'))
inner_source = PythonStringSource(self.basename, pysource,
self.options,
self.printpath, lineno_shift=start+1)
self.printpath,
lineno_shift=start + 1)
inner_doctests, _ = inner_source._create_doctests(namespace, True)
safe_docstring = inner_source._neutralize_doctests(min_indent)
outer_doctest = self.parser.get_doctest(safe_docstring, namespace,
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/graph_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def show(self, max_field_size=20, with_picture=False):
"""
relabel = {}
for col in valid_kwds:
relabel[col] = ' '.join([word.capitalize() for word in col.split('_')])
relabel[col] = ' '.join(word.capitalize() for word in col.split('_'))

if re.search('SELECT .*degree_sequence.* FROM', self.__query_string__):
format_cols = {'degree_sequence': data_to_degseq}
Expand Down
2 changes: 1 addition & 1 deletion src/sage/groups/matrix_gps/matrix_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _latex_(self):
0 & 1
\end{array}\right) \right\rangle
"""
gens = ', '.join([latex(x) for x in self.gens()])
gens = ', '.join(latex(x) for x in self.gens())
return '\\left\\langle %s \\right\\rangle' % gens

def sign_representation(self, base_ring=None, side="twosided"):
Expand Down
5 changes: 3 additions & 2 deletions src/sage/groups/perm_gps/permgroup_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1804,9 +1804,10 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
'(1,3)(2)'
"""
cycles = self.cycle_tuples(singletons)
if len(cycles) == 0:
if not cycles:
return '()'
return ''.join([repr(c) for c in cycles]).replace(', ',',').replace(',)',')')
text = ''.join(repr(c) for c in cycles)
return text.replace(', ', ',').replace(',)', ')')

def cycle_type(self, singletons=True, as_list=False):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/curves/closed_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _repr_(self):
sage: pts[0]
Point (x, y)
"""
return "Point ({})".format(', '.join([repr(g) for g in self.prime_ideal().gens()]))
return "Point ({})".format(', '.join(repr(g) for g in self.prime_ideal().gens()))

def curve(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/schemes/curves/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def _repr_(self):
"""
if self.defining_ideal().is_zero() and self.ambient_space().dimension() == 1:
return "{} Line over {}".format(self._repr_type(), self.base_ring())
else:
return "{} Curve over {} defined by {}".format(self._repr_type(), self.base_ring(),
', '.join([str(x) for x in self.defining_polynomials()]))
return "{} Curve over {} defined by {}".format(self._repr_type(),
self.base_ring(),
', '.join(str(x) for x in self.defining_polynomials()))

def _repr_type(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ def riemann_roch_basis(self, D):
Dcoeffs.append(D.coefficient(coords[x[1]]))
else:
Dcoeffs.append(0)
G = singular(','.join([str(x) for x in Dcoeffs]), type='intvec')
G = singular(','.join(str(x) for x in Dcoeffs), type='intvec')
# call singular's brill noether routine and return
T = X2[1][2]
T.set_ring()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/projective/projective_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def _repr_generic_point(self, v=None):
"""
if v is None:
v = self.gens()
return '(%s)' % (" : ".join([repr(f) for f in v]))
return '(%s)' % (" : ".join(repr(f) for f in v))

def _latex_generic_point(self, v=None):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/stats/time_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ cdef class TimeSeries:
if len(self) > max_print:
v0 = self[:max_print//2]
v1 = self[-max_print//2:]
return '[' + ', '.join([format%x for x in v0]) + ' ... ' + \
', '.join([format%x for x in v1]) + ']'
return '[' + ', '.join(format%x for x in v0) + ' ... ' + \
', '.join(format%x for x in v1) + ']'
else:
return '[' + ', '.join([format%x for x in self]) + ']'
return '[' + ', '.join(format%x for x in self) + ']'

def __len__(self):
"""
Expand Down
9 changes: 5 additions & 4 deletions src/sage/symbolic/pynac_impl.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def py_latex_function_pystring(id, args, fname_paren=False):
olist = [name]
# print the arguments
from sage.misc.latex import latex
olist.extend([r'\left(', ', '.join([latex(x) for x in args]),
olist.extend([r'\left(', ', '.join(latex(x) for x in args),
r'\right)'])
return ''.join(olist)

Expand Down Expand Up @@ -646,10 +646,11 @@ cdef stdstring* py_print_fderivative(unsigned id, params,
- args -- arguments of the function.
"""
if all(tolerant_is_symbol(a) for a in args) and len(set(args)) == len(args):
diffvarstr = ', '.join([repr(args[i]) for i in params])
py_res = ''.join(['diff(',py_print_function_pystring(id,args,False),', ',diffvarstr,')'])
diffvarstr = ', '.join(repr(args[i]) for i in params)
py_res = ''.join(['diff(', py_print_function_pystring(id, args, False),
', ', diffvarstr, ')'])
else:
ostr = ''.join(['D[', ', '.join([repr(int(x)) for x in params]), ']'])
ostr = ''.join(['D[', ', '.join(repr(int(x)) for x in params), ']'])
fstr = py_print_function_pystring(id, args, True)
py_res = ostr + fstr
return string_from_pystr(py_res)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/topology/simplicial_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def _repr_(self):
s_1 s_0 v
"""
if self.degeneracies():
degens = ' '.join(['s_{}'.format(i) for i in self.degeneracies()])
degens = ' '.join(f's_{i}' for i in self.degeneracies())
return degens + ' {}'.format(self.nondegenerate())
return 'Delta^{}'.format(self._dim)

Expand Down Expand Up @@ -903,7 +903,7 @@ def _latex_(self):
else:
simplex = "\\Delta^{{{}}}".format(self._dim)
if self.degeneracies():
degens = ' '.join(['s_{{{}}}'.format(i) for i in self.degeneracies()])
degens = ' '.join(f's_{{{i}}}' for i in self.degeneracies())
return degens + ' ' + simplex
return simplex

Expand Down
24 changes: 12 additions & 12 deletions src/sage/topology/simplicial_set_constructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ def __init__(self, maps=None):
continue

simplex_factors = tuple(zip(simplices, tuple(degens)))
s = '(' + ', '.join(['{}'.format(_[0].apply_degeneracies(*_[1]))
for _ in simplex_factors]) + ')'
ls = '(' + ', '.join(['{}'.format(latex(_[0].apply_degeneracies(*_[1])))
for _ in simplex_factors]) + ')'
s = '(' + ', '.join('{}'.format(_[0].apply_degeneracies(*_[1]))
for _ in simplex_factors) + ')'
ls = '(' + ', '.join('{}'.format(latex(_[0].apply_degeneracies(*_[1])))
for _ in simplex_factors) + ')'
simplex = AbstractSimplex(d, name=s, latex_name=ls)
translate[simplex_factors] = simplex
# Now compute the faces of simplex.
Expand Down Expand Up @@ -968,7 +968,7 @@ def _repr_(self):
sage: S2.product(K, B)
S^2 x Klein bottle x Classifying space of Multiplicative Abelian group isomorphic to C2
"""
return ' x '.join([str(X) for X in self._factors])
return ' x '.join(str(X) for X in self._factors)

def _latex_(self):
r"""
Expand All @@ -983,7 +983,7 @@ def _latex_(self):
sage: latex(S2.product(RPoo, S2))
S^{2} \times RP^{\infty} \times S^{2}
"""
return ' \\times '.join([latex(X) for X in self._factors])
return ' \\times '.join(latex(X) for X in self._factors)


class ProductOfSimplicialSets_finite(ProductOfSimplicialSets, PullbackOfSimplicialSets_finite):
Expand Down Expand Up @@ -1934,7 +1934,7 @@ def _repr_(self):
Smash product: (S^1 ^ RP^4 ^ S^1)
"""
s = 'Smash product: ('
s += ' ^ '.join([str(X) for X in self._factors])
s += ' ^ '.join(str(X) for X in self._factors)
s += ')'
return s

Expand All @@ -1949,7 +1949,7 @@ def _latex_(self):
sage: latex(S1.smash_product(RP4, S1))
S^{1} \wedge RP^{4} \wedge S^{1}
"""
return ' \\wedge '.join([latex(X) for X in self._factors])
return ' \\wedge '.join(latex(X) for X in self._factors)


class WedgeOfSimplicialSets(PushoutOfSimplicialSets, Factors):
Expand Down Expand Up @@ -2039,7 +2039,7 @@ def _repr_(self):
Wedge: (Klein bottle v Klein bottle v Klein bottle)
"""
s = 'Wedge: ('
s += ' v '.join([str(X) for X in self._factors])
s += ' v '.join(str(X) for X in self._factors)
s += ')'
return s

Expand All @@ -2054,7 +2054,7 @@ def _latex_(self):
sage: latex(S1.wedge(RP4, S1))
S^{1} \vee RP^{4} \vee S^{1}
"""
return ' \\vee '.join([latex(X) for X in self._factors])
return ' \\vee '.join(latex(X) for X in self._factors)


class WedgeOfSimplicialSets_finite(WedgeOfSimplicialSets, PushoutOfSimplicialSets_finite):
Expand Down Expand Up @@ -2245,7 +2245,7 @@ def _repr_(self):
Disjoint union: (Torus u Torus u RP^3)
"""
s = 'Disjoint union: ('
s += ' u '.join([str(X) for X in self._factors])
s += ' u '.join(str(X) for X in self._factors)
s += ')'
return s

Expand All @@ -2260,7 +2260,7 @@ def _latex_(self):
sage: latex(S1.disjoint_union(RP4, S1))
S^{1} \amalg RP^{4} \amalg S^{1}
"""
return ' \\amalg '.join([latex(X) for X in self._factors])
return ' \\amalg '.join(latex(X) for X in self._factors)


class DisjointUnionOfSimplicialSets_finite(DisjointUnionOfSimplicialSets,
Expand Down

0 comments on commit b3d6a0b

Please sign in to comment.