diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-01-26 19:02:44 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-01-26 19:02:44 +0000 |
| commit | 579efc8b5dce6d69c4acd1668f94349b2ee0466a (patch) | |
| tree | 33f5f741a997d0ca36a16e1eeef7ce6f0c0c8943 /docutils | |
| parent | fecb04aaa7043888ae7ea560f90dc14f6ff8595d (diff) | |
| download | docutils-579efc8b5dce6d69c4acd1668f94349b2ee0466a.tar.gz | |
Use generator expressions with functions expecting a sequence.
Based on patches by Adam Turner
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@8970 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
| -rw-r--r-- | docutils/docutils/io.py | 2 | ||||
| -rw-r--r-- | docutils/docutils/nodes.py | 12 | ||||
| -rw-r--r-- | docutils/docutils/parsers/rst/directives/__init__.py | 6 | ||||
| -rw-r--r-- | docutils/docutils/parsers/rst/states.py | 2 | ||||
| -rw-r--r-- | docutils/docutils/utils/__init__.py | 6 | ||||
| -rw-r--r-- | docutils/docutils/utils/math/__init__.py | 4 | ||||
| -rw-r--r-- | docutils/docutils/utils/math/latex2mathml.py | 6 | ||||
| -rwxr-xr-x | docutils/docutils/utils/math/math2html.py | 4 | ||||
| -rw-r--r-- | docutils/docutils/utils/math/tex2mathml_extern.py | 4 | ||||
| -rw-r--r-- | docutils/docutils/utils/smartquotes.py | 6 | ||||
| -rw-r--r-- | docutils/docutils/writers/latex2e/__init__.py | 19 | ||||
| -rw-r--r-- | docutils/docutils/writers/odf_odt/__init__.py | 4 | ||||
| -rw-r--r-- | docutils/docutils/writers/s5_html/__init__.py | 2 | ||||
| -rwxr-xr-x | docutils/test/test_parsers/test_rst/test_tables.py | 12 | ||||
| -rwxr-xr-x | docutils/tools/dev/unicode2rstsubs.py | 4 | ||||
| -rwxr-xr-x | docutils/tools/quicktest.py | 4 |
16 files changed, 48 insertions, 49 deletions
diff --git a/docutils/docutils/io.py b/docutils/docutils/io.py index 46d3c6bf7..ecc24065d 100644 --- a/docutils/docutils/io.py +++ b/docutils/docutils/io.py @@ -145,7 +145,7 @@ class Input(TransformSpec): 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.]+)") diff --git a/docutils/docutils/nodes.py b/docutils/docutils/nodes.py index a971c7dc2..e379d856e 100644 --- a/docutils/docutils/nodes.py +++ b/docutils/docutils/nodes.py @@ -553,7 +553,7 @@ class Element(Node): 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 @@ class Element(Node): 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 @@ class pending(Special, Invisible, Element): 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, diff --git a/docutils/docutils/parsers/rst/directives/__init__.py b/docutils/docutils/parsers/rst/directives/__init__.py index cc469c10c..dbd8b855d 100644 --- a/docutils/docutils/parsers/rst/directives/__init__.py +++ b/docutils/docutils/parsers/rst/directives/__init__.py @@ -184,7 +184,7 @@ def path(argument): 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 @@ def get_measure(argument, units): 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 @@ def choice(argument, values): % (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): diff --git a/docutils/docutils/parsers/rst/states.py b/docutils/docutils/parsers/rst/states.py index 55b01e4b6..c776999e6 100644 --- a/docutils/docutils/parsers/rst/states.py +++ b/docutils/docutils/parsers/rst/states.py @@ -1980,7 +1980,7 @@ class Body(RSTState): - '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 diff --git a/docutils/docutils/utils/__init__.py b/docutils/docutils/utils/__init__.py index 6cd0a38c9..4b80b7ed2 100644 --- a/docutils/docutils/utils/__init__.py +++ b/docutils/docutils/utils/__init__.py @@ -597,7 +597,7 @@ def split_escaped_whitespace(text): 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 @@ def column_width(text): 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 diff --git a/docutils/docutils/utils/math/__init__.py b/docutils/docutils/utils/math/__init__.py index 3e18434b8..4f210a9c2 100644 --- a/docutils/docutils/utils/math/__init__.py +++ b/docutils/docutils/utils/math/__init__.py @@ -28,8 +28,8 @@ It contains various modules for conversion between different math formats 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`. diff --git a/docutils/docutils/utils/math/latex2mathml.py b/docutils/docutils/utils/math/latex2mathml.py index e65879efd..5bbae315d 100644 --- a/docutils/docutils/utils/math/latex2mathml.py +++ b/docutils/docutils/utils/math/latex2mathml.py @@ -412,10 +412,10 @@ class math(object): + ['</%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 = [] diff --git a/docutils/docutils/utils/math/math2html.py b/docutils/docutils/utils/math/math2html.py index 9f57eeb69..f9b94a27d 100755 --- a/docutils/docutils/utils/math/math2html.py +++ b/docutils/docutils/utils/math/math2html.py @@ -1653,7 +1653,7 @@ class FormulaBit(Container): "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 @@ class BracketProcessor(MathsProcessor): 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." diff --git a/docutils/docutils/utils/math/tex2mathml_extern.py b/docutils/docutils/utils/math/tex2mathml_extern.py index 8fda1605b..b68ecc191 100644 --- a/docutils/docutils/utils/math/tex2mathml_extern.py +++ b/docutils/docutils/utils/math/tex2mathml_extern.py @@ -90,8 +90,8 @@ def ttm(math_code, reporter=None): 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) diff --git a/docutils/docutils/utils/smartquotes.py b/docutils/docutils/utils/smartquotes.py index ad8e7e6ef..7591bd2c6 100644 --- a/docutils/docutils/utils/smartquotes.py +++ b/docutils/docutils/utils/smartquotes.py @@ -502,8 +502,8 @@ class smartchars(object): 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 @@ if __name__ == "__main__": # 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 diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py index ddaf15584..78716f212 100644 --- a/docutils/docutils/writers/latex2e/__init__.py +++ b/docutils/docutils/writers/latex2e/__init__.py @@ -428,7 +428,7 @@ class Babel(object): 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 @@ class Table(object): 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 @@ class Table(object): 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 @@ class LaTeXTranslator(nodes.NodeVisitor): """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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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', '') diff --git a/docutils/docutils/writers/odf_odt/__init__.py b/docutils/docutils/writers/odf_odt/__init__.py index 74b35c4b2..3e8b5e72d 100644 --- a/docutils/docutils/writers/odf_odt/__init__.py +++ b/docutils/docutils/writers/odf_odt/__init__.py @@ -2873,9 +2873,9 @@ class ODFTranslator(nodes.GenericNodeVisitor): 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) diff --git a/docutils/docutils/writers/s5_html/__init__.py b/docutils/docutils/writers/s5_html/__init__.py index 6514f8af9..16dcf7c1a 100644 --- a/docutils/docutils/writers/s5_html/__init__.py +++ b/docutils/docutils/writers/s5_html/__init__.py @@ -242,7 +242,7 @@ class S5HTMLTranslator(html4css1.HTMLTranslator): 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$') diff --git a/docutils/test/test_parsers/test_rst/test_tables.py b/docutils/test/test_parsers/test_rst/test_tables.py index 50cee7f79..be742509c 100755 --- a/docutils/test/test_parsers/test_rst/test_tables.py +++ b/docutils/test/test_parsers/test_rst/test_tables.py @@ -571,8 +571,8 @@ No blank line after table. | (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 before. 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 @@ Inclusion .. include:: 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> diff --git a/docutils/tools/dev/unicode2rstsubs.py b/docutils/tools/dev/unicode2rstsubs.py index 5727a1cf0..182a44040 100755 --- a/docutils/tools/dev/unicode2rstsubs.py +++ b/docutils/tools/dev/unicode2rstsubs.py @@ -170,7 +170,7 @@ class CharacterEntitySetExtractor(object): 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 @@ class CharacterEntitySetExtractor(object): 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])) diff --git a/docutils/tools/quicktest.py b/docutils/tools/quicktest.py index 0ada37da7..5294cc9ce 100755 --- a/docutils/tools/quicktest.py +++ b/docutils/tools/quicktest.py @@ -128,8 +128,8 @@ def getArgs(): 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) |
