diff options
author | JensDiemer <git@jensdiemer.de> | 2021-05-11 16:36:56 +0200 |
---|---|---|
committer | JensDiemer <git@jensdiemer.de> | 2021-05-11 16:36:56 +0200 |
commit | 4c48b34e9332012f88ae61eb4d47f3b8ac26f523 (patch) | |
tree | 4736f50ffb25d5b55e379b07e65d129aeb71b369 /creole | |
parent | f0766f1859a227134d2314491821b85f360bc202 (diff) | |
download | creole-4c48b34e9332012f88ae61eb4d47f3b8ac26f523.tar.gz |
Code cleanup: Use f-strings and generator in join() calls
Diffstat (limited to 'creole')
-rw-r--r-- | creole/emitter/creol2html_emitter.py | 2 | ||||
-rw-r--r-- | creole/emitter/html2rest_emitter.py | 4 | ||||
-rw-r--r-- | creole/html_tools/strip_html.py | 2 | ||||
-rw-r--r-- | creole/rest_tools/clean_writer.py | 2 | ||||
-rw-r--r-- | creole/shared/markup_table.py | 6 | ||||
-rw-r--r-- | creole/tests/test_creole2html.py | 2 | ||||
-rw-r--r-- | creole/tests/test_macros.py | 2 | ||||
-rw-r--r-- | creole/tests/utils/utils.py | 4 |
8 files changed, 12 insertions, 12 deletions
diff --git a/creole/emitter/creol2html_emitter.py b/creole/emitter/creol2html_emitter.py index e8689b3..dc028a7 100644 --- a/creole/emitter/creol2html_emitter.py +++ b/creole/emitter/creol2html_emitter.py @@ -388,7 +388,7 @@ class HtmlEmitter: def emit_children(self, node): """Emit all the children of a node.""" - return ''.join([self.emit_node(child) for child in node.children]) + return ''.join(self.emit_node(child) for child in node.children) def emit_node(self, node): """Emit a single node.""" diff --git a/creole/emitter/html2rest_emitter.py b/creole/emitter/html2rest_emitter.py index d2d9042..64891ca 100644 --- a/creole/emitter/html2rest_emitter.py +++ b/creole/emitter/html2rest_emitter.py @@ -58,7 +58,7 @@ class ReStructuredTextEmitter(BaseEmitter): def blockdata_pre_emit(self, node): """ pre block -> with newline at the end """ pre_block = self.deentity.replace_all(node.content).strip() - pre_block = "\n".join([" %s" % line for line in pre_block.splitlines()]) + pre_block = "\n".join(f" {line}" for line in pre_block.splitlines()) return f"::\n\n{pre_block}\n\n" def inlinedata_pre_emit(self, node): @@ -267,7 +267,7 @@ class ReStructuredTextEmitter(BaseEmitter): if node.level == 1: # FIXME: This should be made easier and better - complete_list = "\n\n".join([i.strip("\n") for i in content.split("\n") if i]) + complete_list = "\n\n".join(i.strip("\n") for i in content.split("\n") if i) content = f"{complete_list}\n\n" return content diff --git a/creole/html_tools/strip_html.py b/creole/html_tools/strip_html.py index d8dbac3..c4b2c71 100644 --- a/creole/html_tools/strip_html.py +++ b/creole/html_tools/strip_html.py @@ -95,7 +95,7 @@ def strip_html(html_code): return result data = html_code.strip() - clean_data = " ".join([line.strip() for line in data.split("\n")]) + clean_data = " ".join(line.strip() for line in data.split("\n")) clean_data = strip_html_regex.sub(strip_tag, clean_data) return clean_data diff --git a/creole/rest_tools/clean_writer.py b/creole/rest_tools/clean_writer.py index e55361d..ca69f22 100644 --- a/creole/rest_tools/clean_writer.py +++ b/creole/rest_tools/clean_writer.py @@ -91,7 +91,7 @@ class CleanHTMLTranslator(html4css1.HTMLTranslator): continue if isinstance(value, list): - value = ' '.join([str(x) for x in value]) + value = ' '.join(str(x) for x in value) part = f'{name.lower()}="{self.attval(str(value))}"' parts.append(part) diff --git a/creole/shared/markup_table.py b/creole/shared/markup_table.py index 444aae9..54b4763 100644 --- a/creole/shared/markup_table.py +++ b/creole/shared/markup_table.py @@ -60,7 +60,7 @@ class MarkupTable: if not self.auto_width: lines = [] for row in self.rows: - lines.append("|" + "|".join([cell for cell in row]) + "|") + lines.append("|" + "|".join(cell for cell in row) + "|") else: # preformat every table cell cells, widths = self._get_preformat_info() @@ -81,8 +81,8 @@ class MarkupTable: # preformat every table cell cells, widths = self._get_preformat_info() - separator_line = f"+{'+'.join([('-' * width) for width in widths])}+" - headline_separator = f"+{'+'.join([('=' * width) for width in widths])}+" + separator_line = f"+{'+'.join(('-' * width) for width in widths)}+" + headline_separator = f"+{'+'.join(('=' * width) for width in widths)}+" lines = [] for no, row in enumerate(cells): diff --git a/creole/tests/test_creole2html.py b/creole/tests/test_creole2html.py index e2d2a0a..0c36170 100644 --- a/creole/tests/test_creole2html.py +++ b/creole/tests/test_creole2html.py @@ -66,7 +66,7 @@ class TestCreole2html(BaseCreoleTest): tb_lines = [" -" * 40] tb_lines += error_msg.splitlines() tb_lines += [" -" * 40] - tb = "\n".join([" >>> %s" % line for line in tb_lines]) + tb = "\n".join(f" >>> {line}" for line in tb_lines) msg = f"{part!r} not found in:\n{tb}" # TODO: use assertIn if python 2.6 will be not support anymore. if part not in error_msg: diff --git a/creole/tests/test_macros.py b/creole/tests/test_macros.py index 1a69b36..54c385a 100644 --- a/creole/tests/test_macros.py +++ b/creole/tests/test_macros.py @@ -23,7 +23,7 @@ def unittest_macro1(**kwargs): >>> unittest_macro1(a=1,b=2) '[test macro1 - kwargs: a=1,b=2]' """ - kwargs = ','.join('{}={}'.format(k, json.dumps(v)) for k, v in sorted(kwargs.items())) + kwargs = ','.join(f'{k}={json.dumps(v)}' for k, v in sorted(kwargs.items())) return f"[test macro1 - kwargs: {kwargs}]" diff --git a/creole/tests/utils/utils.py b/creole/tests/utils/utils.py index d9fbf29..126ac36 100644 --- a/creole/tests/utils/utils.py +++ b/creole/tests/utils/utils.py @@ -32,9 +32,9 @@ class MarkupTest(unittest.TestCase): def _format_output(self, txt): txt = txt.split("\\n") if self.VERBOSE == 1: - txt = "".join(['%s\\n\n' % i for i in txt]) + txt = "".join(f'{i}\\n\n' for i in txt) elif self.VERBOSE == 2: - txt = "".join(['%s\n' % i for i in txt]) + txt = "".join(f'{i}\n' for i in txt) return txt def assertEqual(self, first, second, msg=""): |