|
From: <mi...@us...> - 2022-01-26 19:02:48
|
Revision: 8970
http://sourceforge.net/p/docutils/code/8970
Author: milde
Date: 2022-01-26 19:02:44 +0000 (Wed, 26 Jan 2022)
Log Message:
-----------
Use generator expressions with functions expecting a sequence.
Based on patches by Adam Turner
Modified Paths:
--------------
trunk/docutils/docutils/io.py
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/parsers/rst/directives/__init__.py
trunk/docutils/docutils/parsers/rst/states.py
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/docutils/utils/math/__init__.py
trunk/docutils/docutils/utils/math/latex2mathml.py
trunk/docutils/docutils/utils/math/math2html.py
trunk/docutils/docutils/utils/math/tex2mathml_extern.py
trunk/docutils/docutils/utils/smartquotes.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/docutils/writers/odf_odt/__init__.py
trunk/docutils/docutils/writers/s5_html/__init__.py
trunk/docutils/test/test_parsers/test_rst/test_tables.py
trunk/docutils/tools/dev/unicode2rstsubs.py
trunk/docutils/tools/quicktest.py
Modified: trunk/docutils/docutils/io.py
===================================================================
--- trunk/docutils/docutils/io.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/io.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -145,7 +145,7 @@
error = err
raise UnicodeError(
'Unable to decode input data. Tried the following encodings: '
- '%s.\n(%s)' % (', '.join([repr(enc) for enc in encodings]),
+ '%s.\n(%s)' % (', '.join(repr(enc) for enc in encodings),
error_string(error)))
coding_slug = re.compile(br"coding[:=]\s*([-\w.]+)")
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/nodes.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -553,7 +553,7 @@
element = domroot.createElement(self.tagname)
for attribute, value in self.attlist():
if isinstance(value, list):
- value = ' '.join([serial_escape('%s' % (v,)) for v in value])
+ value = ' '.join(serial_escape('%s' % (v,)) for v in value)
element.setAttribute(attribute, '%s' % value)
for child in self.children:
element.appendChild(child._dom_node(domroot))
@@ -581,9 +581,9 @@
def __str__(self):
if self.children:
- return u'%s%s%s' % (self.starttag(),
- ''.join([str(c) for c in self.children]),
- self.endtag())
+ return '%s%s%s' % (self.starttag(),
+ ''.join(str(c) for c in self.children),
+ self.endtag())
else:
return self.emptytag()
@@ -1867,8 +1867,8 @@
else:
internals.append('%7s%s: %r' % ('', key, value))
return (Element.pformat(self, indent, level)
- + ''.join([(' %s%s\n' % (indent * level, line))
- for line in internals]))
+ + ''.join((' %s%s\n' % (indent * level, line))
+ for line in internals))
def copy(self):
obj = self.__class__(self.transform, self.details, self.rawsource,
Modified: trunk/docutils/docutils/parsers/rst/directives/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/__init__.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/parsers/rst/directives/__init__.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -184,7 +184,7 @@
if argument is None:
raise ValueError('argument required but none supplied')
else:
- path = ''.join([s.strip() for s in argument.splitlines()])
+ path = ''.join(s.strip() for s in argument.splitlines())
return path
def uri(argument):
@@ -239,7 +239,7 @@
except (AttributeError, ValueError):
raise ValueError(
'not a positive measure of one of the following units:\n%s'
- % ' '.join(['"%s"' % i for i in units]))
+ % ' '.join('"%s"' % i for i in units))
return match.group(1) + match.group(2)
def length_or_unitless(argument):
@@ -404,7 +404,7 @@
% (argument, format_values(values)))
def format_values(values):
- return '%s, or "%s"' % (', '.join(['"%s"' % s for s in values[:-1]]),
+ return '%s, or "%s"' % (', '.join('"%s"' % s for s in values[:-1]),
values[-1])
def value_or(values, other):
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/parsers/rst/states.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -1980,7 +1980,7 @@
- 'malformed' and a system_message node
"""
if block and block[-1].strip()[-1:] == '_': # possible indirect target
- reference = ' '.join([line.strip() for line in block])
+ reference = ' '.join(line.strip() for line in block)
refname = self.is_reference(reference)
if refname:
return 'refname', refname
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/utils/__init__.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -597,7 +597,7 @@
return list(itertools.chain(*strings))
def strip_combining_chars(text):
- return u''.join([c for c in text if not unicodedata.combining(c)])
+ return ''.join(c for c in text if not unicodedata.combining(c))
def find_combining_chars(text):
"""Return indices of all combining chars in Unicode string `text`.
@@ -639,8 +639,8 @@
Correct ``len(text)`` for wide East Asian and combining Unicode chars.
"""
- width = sum([east_asian_widths[unicodedata.east_asian_width(c)]
- for c in text])
+ width = sum(east_asian_widths[unicodedata.east_asian_width(c)]
+ for c in text)
# correction for combining chars:
width -= len(find_combining_chars(text))
return width
Modified: trunk/docutils/docutils/utils/math/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/math/__init__.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/utils/math/__init__.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -28,8 +28,8 @@
def toplevel_code(code):
"""Return string (LaTeX math) `code` with environments stripped out."""
chunks = code.split(r'\begin{')
- return r'\begin{'.join([chunk.split(r'\end{')[-1]
- for chunk in chunks])
+ return r'\begin{'.join(chunk.split(r'\end{')[-1]
+ for chunk in chunks)
def pick_math_environment(code, numbered=False):
"""Return the right math environment to display `code`.
Modified: trunk/docutils/docutils/utils/math/latex2mathml.py
===================================================================
--- trunk/docutils/docutils/utils/math/latex2mathml.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/utils/math/latex2mathml.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -412,10 +412,10 @@
+ ['</%s>' % self.__class__.__name__])
def xml_starttag(self):
- attrs = ['%s="%s"' % (k, str(v).replace('True', 'true').replace('False', 'false'))
+ attrs = ('%s="%s"' % (k, str(v).replace('True', 'true').replace('False', 'false'))
for k, v in self.attributes.items()
- if v is not None]
- return '<%s>' % ' '.join([self.__class__.__name__] + attrs)
+ if v is not None)
+ return '<%s>' % ' '.join((self.__class__.__name__, *attrs))
def _xml_body(self, level=0):
xml = []
Modified: trunk/docutils/docutils/utils/math/math2html.py
===================================================================
--- trunk/docutils/docutils/utils/math/math2html.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/utils/math/math2html.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -1653,7 +1653,7 @@
"Compute the size of the bit as the max of the sizes of all contents."
if len(self.contents) == 0:
return 1
- self.size = max([element.size for element in self.contents])
+ self.size = max(element.size for element in self.contents)
return self.size
def clone(self):
@@ -2848,7 +2848,7 @@
def findmax(self, contents, leftindex, rightindex):
"Find the max size of the contents between the two given indices."
sliced = contents[leftindex:rightindex]
- return max([element.size for element in sliced])
+ return max(element.size for element in sliced)
def resize(self, command, size):
"Resize a bracket command to the given size."
Modified: trunk/docutils/docutils/utils/math/tex2mathml_extern.py
===================================================================
--- trunk/docutils/docutils/utils/math/tex2mathml_extern.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/utils/math/tex2mathml_extern.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -90,8 +90,8 @@
result = p.stdout.read()
err = p.stderr.read().decode('utf8')
if err.find('**** Unknown') >= 0:
- msg = '\n'.join([line for line in err.splitlines()
- if line.startswith('****')])
+ msg = '\n'.join(line for line in err.splitlines()
+ if line.startswith('****'))
raise SyntaxError('\nMessage from external converter TtM:\n'+ msg)
if reporter and err.find('**** Error') >= 0 or not result:
reporter.error(err)
Modified: trunk/docutils/docutils/utils/smartquotes.py
===================================================================
--- trunk/docutils/docutils/utils/smartquotes.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/utils/smartquotes.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -502,8 +502,8 @@
def smartyPants(text, attr=default_smartypants_attr, language='en'):
"""Main function for "traditional" use."""
- return "".join([t for t in educate_tokens(tokenize(text),
- attr, language)])
+ return "".join(t for t in educate_tokens(tokenize(text),
+ attr, language))
def educate_tokens(text_tokens, attr=default_smartypants_attr, language='en'):
@@ -926,7 +926,7 @@
# find all combinations of subtags
for n in range(len(_subtags), 0, -1):
for tags in itertools.combinations(_subtags, n):
- _tag = '-'.join((_basetag,)+tags)
+ _tag = '-'.join((_basetag, *tags))
if _tag in smartchars.quotes:
defaultlanguage = _tag
break
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -428,7 +428,7 @@
self.setup = [r'\usepackage[%s]{babel}' % ','.join(languages)]
# Deactivate "active characters"
shorthands = []
- for c in ''.join([self.active_chars.get(l, '') for l in languages]):
+ for c in ''.join(self.active_chars.get(l, '') for l in languages):
if c not in shorthands:
shorthands.append(c)
if shorthands:
@@ -995,9 +995,8 @@
def get_multicolumn_width(self, start, len_):
"""Return sum of columnwidths for multicell."""
try:
- multicol_width = sum([width
- for width in ([self._colwidths[start + co]
- for co in range(len_)])])
+ multicol_width = sum(self._colwidths[start + co]
+ for co in range(len_))
if self.legacy_column_widths:
return 'p{%.2f\\DUtablewidth}' % multicol_width
return 'p{\\DUcolumnwidth{%.3f}}' % multicol_width
@@ -1038,7 +1037,7 @@
n_c = len(self._col_specs)
a.append('\\endhead\n')
# footer on all but last page (if it fits):
- twidth = sum([node['colwidth']+2 for node in self._col_specs])
+ twidth = sum(node['colwidth']+2 for node in self._col_specs)
if twidth > 30 or (twidth > 12 and not self.colwidths_auto):
a.append(r'\multicolumn{%d}{%s}'
% (n_c, self.get_multicolumn_width(0, n_c))
@@ -1566,8 +1565,8 @@
"""Append hypertargets for all ids of `node`"""
# hypertarget places the anchor at the target's baseline,
# so we raise it explicitly
- self.out.append('%\n'.join(['\\raisebox{1em}{\\hypertarget{%s}{}}' %
- id for id in node['ids']]))
+ self.out.append('%\n'.join('\\raisebox{1em}{\\hypertarget{%s}{}}' %
+ id for id in node['ids']))
def ids_to_labels(self, node, set_anchor=True, protect=False,
newline=False):
@@ -2157,9 +2156,9 @@
if self.compound_enumerators:
if (self.section_prefix_for_enumerators and self.section_level
and not self._enumeration_counters):
- prefix = '.'.join([str(n) for n in
- self._section_number[:self.section_level]]
- ) + self.section_enumerator_separator
+ prefix = '.'.join(str(n) for n in
+ self._section_number[:self.section_level]
+ ) + self.section_enumerator_separator
if self._enumeration_counters:
prefix += self._enumeration_counters[-1]
prefix += node.get('prefix', '')
Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -2873,9 +2873,9 @@
formatlist = formats.split()
if 'odt' in formatlist:
rawstr = node.astext()
- attrstr = ' '.join([
+ attrstr = ' '.join(
'%s="%s"' % (k, v, )
- for k, v in list(CONTENT_NAMESPACE_ATTRIB.items())])
+ for k, v in list(CONTENT_NAMESPACE_ATTRIB.items()))
contentstr = '<stuff %s>%s</stuff>' % (attrstr, rawstr, )
contentstr = contentstr.encode("utf-8")
content = etree.fromstring(contentstr)
Modified: trunk/docutils/docutils/writers/s5_html/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/s5_html/__init__.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/docutils/writers/s5_html/__init__.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -242,7 +242,7 @@
required.remove(f)
raise docutils.ApplicationError(
'Theme files not found: %s'
- % ', '.join(['%r' % f for f in required]))
+ % ', '.join('%r' % f for f in required))
files_to_skip_pattern = re.compile(r'~$|\.bak$|#$|\.cvsignore$')
Modified: trunk/docutils/test/test_parsers/test_rst/test_tables.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_tables.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/test/test_parsers/test_rst/test_tables.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -571,8 +571,8 @@
| (The first cell of this table may expand |
| to accommodate long filesystem paths.) |
+------------------------------------------------------------------------------+
-""") % ('\n'.join(['| %-70s |' % include2[part * 70 : (part + 1) * 70]
- for part in range(len(include2) // 70 + 1)])),
+""") % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70]
+ for part in range(len(include2) // 70 + 1))),
"""\
<document source="test data">
<table>
@@ -606,8 +606,8 @@
Something afterwards.
And more.
-""") % ('\n'.join(['| %-70s |' % include2[part * 70 : (part + 1) * 70]
- for part in range(len(include2) // 70 + 1)])),
+""") % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70]
+ for part in range(len(include2) // 70 + 1))),
"""\
<document source="test data">
<paragraph>
@@ -1274,8 +1274,8 @@
Note The first row of this table may expand
to accommodate long filesystem paths.
========= =====================================================================
-""" % ('\n'.join([' %-65s' % include2[part * 65 : (part + 1) * 65]
- for part in range(len(include2) // 65 + 1)])),
+""" % ('\n'.join(' %-65s' % include2[part * 65 : (part + 1) * 65]
+ for part in range(len(include2) // 65 + 1))),
"""\
<document source="test data">
<table>
Modified: trunk/docutils/tools/dev/unicode2rstsubs.py
===================================================================
--- trunk/docutils/tools/dev/unicode2rstsubs.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/tools/dev/unicode2rstsubs.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -170,7 +170,7 @@
print('writing file "%s"' % outname)
outfile.write(self.header + '\n')
set = self.sets[set_name]
- entities = sorted([(e.lower(), e) for e in set.keys()])
+ entities = sorted((e.lower(), e) for e in set.keys())
longest = 0
for _, entity_name in entities:
longest = max(longest, len(entity_name))
@@ -188,7 +188,7 @@
for code in charid[1:].split('-'):
if int(code, 16) > 0xFFFF:
return 1 # wide-Unicode character
- codes = ' '.join(['U+%s' % code for code in charid[1:].split('-')])
+ codes = ' '.join('U+%s' % code for code in charid[1:].split('-'))
outfile.write('.. %-*s unicode:: %s .. %s\n'
% (longest + 2, '|' + entity_name + '|',
codes, self.descriptions[charid]))
Modified: trunk/docutils/tools/quicktest.py
===================================================================
--- trunk/docutils/tools/quicktest.py 2022-01-26 19:02:28 UTC (rev 8969)
+++ trunk/docutils/tools/quicktest.py 2022-01-26 19:02:44 UTC (rev 8970)
@@ -128,8 +128,8 @@
def posixGetArgs(argv):
outputFormat = 'pretty'
# convert fancy_getopt style option list to getopt.getopt() arguments
- shortopts = ''.join([option[1] + ':' * (option[0][-1:] == '=')
- for option in options if option[1]])
+ shortopts = ''.join(option[1] + ':' * (option[0][-1:] == '=')
+ for option in options if option[1])
longopts = [option[0] for option in options if option[0]]
try:
opts, args = getopt.getopt(argv, shortopts, longopts)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|