diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-03-03 22:15:00 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-03-03 22:15:00 +0000 |
| commit | 49dc90366c0e596d2f3bf0d98e7eb723ab1f166c (patch) | |
| tree | cb2cf9e02eb26a8731f09603af14187f639ff4f3 | |
| parent | f4062567a7d2c40e2aa0a799574c919c9ebb1eac (diff) | |
| download | docutils-49dc90366c0e596d2f3bf0d98e7eb723ab1f166c.tar.gz | |
Fix whitespace before/after delimiters and colon.
Flake rules
E201 whitespace after '('
E202 whitespace before '}'
E203 whitespace before ':'
E211 whitespace before '('
Exception: : as binary operator in extended slices
(cf. https://www.python.org/dev/peps/pep-0008/#pet-peeves).
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9015 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
21 files changed, 86 insertions, 88 deletions
diff --git a/docutils/docutils/languages/he.py b/docutils/docutils/languages/he.py index b17ef33ba..b237dceb4 100644 --- a/docutils/docutils/languages/he.py +++ b/docutils/docutils/languages/he.py @@ -30,7 +30,7 @@ labels = { 'attention': '\u05ea\u05e9\u05d5\u05de\u05ea \u05dc\u05d1', 'caution': '\u05d6\u05d4\u05d9\u05e8\u05d5\u05ea', 'danger': '\u05e1\u05db\u05e0\u05d4', - 'error': '\u05e9\u05d2\u05d9\u05d0\u05d4' , + 'error': '\u05e9\u05d2\u05d9\u05d0\u05d4', 'hint': '\u05e8\u05de\u05d6', 'important': '\u05d7\u05e9\u05d5\u05d1', 'note': '\u05d4\u05e2\u05e8\u05d4', diff --git a/docutils/docutils/languages/sv.py b/docutils/docutils/languages/sv.py index 43310804e..7cb785fd8 100644 --- a/docutils/docutils/languages/sv.py +++ b/docutils/docutils/languages/sv.py @@ -35,7 +35,7 @@ labels = { 'note': 'Notera', 'tip': 'Tips', 'warning': 'Varning', - 'contents': 'Innehåll' } + 'contents': 'Innehåll'} """Mapping of node class name to label text.""" bibliographic_fields = { @@ -51,7 +51,7 @@ bibliographic_fields = { 'datum': 'date', 'copyright': 'copyright', 'dedikation': 'dedication', - 'sammanfattning': 'abstract' } + 'sammanfattning': 'abstract'} """Swedish (lowcased) to canonical name mapping for bibliographic fields.""" author_separators = [';', ','] diff --git a/docutils/docutils/parsers/rst/languages/he.py b/docutils/docutils/parsers/rst/languages/he.py index b9fc47247..8cc206b97 100644 --- a/docutils/docutils/parsers/rst/languages/he.py +++ b/docutils/docutils/parsers/rst/languages/he.py @@ -21,7 +21,7 @@ directives = { '\u05d6\u05d4\u05d9\u05e8\u05d5\u05ea': 'caution', 'code (translation required)': 'code', '\u05e1\u05db\u05e0\u05d4': 'danger', - '\u05e9\u05d2\u05d9\u05d0\u05d4' : 'error', + '\u05e9\u05d2\u05d9\u05d0\u05d4': 'error', '\u05e8\u05de\u05d6': 'hint', '\u05d7\u05e9\u05d5\u05d1': 'important', '\u05d4\u05e2\u05e8\u05d4': 'note', diff --git a/docutils/docutils/parsers/rst/states.py b/docutils/docutils/parsers/rst/states.py index c57dfd436..10cd92193 100644 --- a/docutils/docutils/parsers/rst/states.py +++ b/docutils/docutils/parsers/rst/states.py @@ -1356,8 +1356,8 @@ class Body(RSTState): break # yes; keep `format` else: # shouldn't happen raise ParserError('enumerator format not matched') - text = groupdict[format][self.enum.formatinfo[format].start - :self.enum.formatinfo[format].end] + text = groupdict[format][self.enum.formatinfo[format].start # noqa: E203 + : self.enum.formatinfo[format].end] if text == '#': sequence = '#' elif expected_sequence: @@ -1408,8 +1408,8 @@ class Body(RSTState): if result: next_enumerator, auto_enumerator = result try: - if ( next_line.startswith(next_enumerator) or - next_line.startswith(auto_enumerator) ): + if (next_line.startswith(next_enumerator) + or next_line.startswith(auto_enumerator)): return 1 except TypeError: pass @@ -2135,7 +2135,7 @@ class Body(RSTState): ) = self.state_machine.get_first_known_indented(match.end(), strip_top=0) block_text = '\n'.join(self.state_machine.input_lines[ - initial_line_offset : self.state_machine.line_offset + 1]) + initial_line_offset : self.state_machine.line_offset + 1]) # noqa: E203 try: arguments, options, content, content_offset = ( self.parse_directive_block(indented, line_offset, @@ -2554,11 +2554,11 @@ class EnumeratedList(SpecializedBody): """Enumerated list item.""" format, sequence, text, ordinal = self.parse_enumerator( match, self.parent['enumtype']) - if ( format != self.format - or (sequence != '#' and (sequence != self.parent['enumtype'] - or self.auto - or ordinal != (self.lastordinal + 1))) - or not self.is_enumerated_list_item(ordinal, sequence, format)): + if (format != self.format + or (sequence != '#' and (sequence != self.parent['enumtype'] + or self.auto + or ordinal != (self.lastordinal + 1))) + or not self.is_enumerated_list_item(ordinal, sequence, format)): # different enumeration: new list self.invalid_input() if sequence == '#': diff --git a/docutils/docutils/statemachine.py b/docutils/docutils/statemachine.py index 2a8856b95..984a3a36c 100644 --- a/docutils/docutils/statemachine.py +++ b/docutils/docutils/statemachine.py @@ -1144,8 +1144,9 @@ class ViewList: self.items[i.start:i.stop] = item.items assert len(self.data) == len(self.items), 'data mismatch' if self.parent: - self.parent[(i.start or 0) + self.parent_offset - : (i.stop or len(self)) + self.parent_offset] = item + k = (i.start or 0) + self.parent_offset + l = (i.stop or len(self)) + self.parent_offset + self.parent[k:l] = item else: self.data[i] = item if self.parent: @@ -1162,8 +1163,9 @@ class ViewList: del self.data[i.start:i.stop] del self.items[i.start:i.stop] if self.parent: - del self.parent[(i.start or 0) + self.parent_offset - : (i.stop or len(self)) + self.parent_offset] + k = (i.start or 0) + self.parent_offset + l = (i.stop or len(self)) + self.parent_offset + del self.parent[k:l] def __add__(self, other): if isinstance(other, ViewList): diff --git a/docutils/docutils/transforms/parts.py b/docutils/docutils/transforms/parts.py index c2c8ab3c4..38707ee48 100644 --- a/docutils/docutils/transforms/parts.py +++ b/docutils/docutils/transforms/parts.py @@ -128,8 +128,8 @@ class Contents(Transform): suggested_prefix='toc-entry') entry = nodes.paragraph('', '', reference) item = nodes.list_item('', entry) - if ( self.backlinks in ('entry', 'top') - and title.next_node(nodes.reference) is None): + if (self.backlinks in ('entry', 'top') + and title.next_node(nodes.reference) is None): if self.backlinks == 'entry': title['refid'] = ref_id elif self.backlinks == 'top': diff --git a/docutils/docutils/utils/math/math2html.py b/docutils/docutils/utils/math/math2html.py index c4127397c..c26963f7b 100755 --- a/docutils/docutils/utils/math/math2html.py +++ b/docutils/docutils/utils/math/math2html.py @@ -1301,7 +1301,7 @@ class TextPosition(Position): "Extract the next string of the given length, or None if not enough text." if self.pos + length > len(self.text): return None - return self.text[self.pos : self.pos + length] + return self.text[self.pos : self.pos + length] # noqa: E203 class Container: diff --git a/docutils/docutils/writers/_html_base.py b/docutils/docutils/writers/_html_base.py index c7c69c88e..2f305cb37 100644 --- a/docutils/docutils/writers/_html_base.py +++ b/docutils/docutils/writers/_html_base.py @@ -1414,8 +1414,8 @@ class HTMLTranslator(nodes.NodeVisitor): atts = {'class': 'reference'} if 'refuri' in node: atts['href'] = node['refuri'] - if ( self.settings.cloak_email_addresses - and atts['href'].startswith('mailto:')): + if (self.settings.cloak_email_addresses + and atts['href'].startswith('mailto:')): atts['href'] = self.cloak_mailto(atts['href']) self.in_mailto = True atts['class'] += ' external' diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index f56a7ec78..b0d8020f4 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -458,8 +458,8 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): atts['class'] = 'docinfo-name' else: atts['class'] = 'field-name' - if ( self.settings.field_name_limit - and len(node.astext()) > self.settings.field_name_limit): + if (self.settings.field_name_limit + and len(node.astext()) > self.settings.field_name_limit): atts['colspan'] = 2 self.context.append('</tr>\n' + self.starttag(node.parent, 'tr', '', @@ -674,8 +674,8 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): # use table for option list def visit_option_group(self, node): atts = {} - if ( self.settings.option_limit - and len(node.astext()) > self.settings.option_limit): + if (self.settings.option_limit + and len(node.astext()) > self.settings.option_limit): atts['colspan'] = 2 self.context.append('</tr>\n<tr><td> </td>') else: @@ -733,9 +733,9 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): return False parent_length = len([n for n in node.parent if not isinstance( n, (nodes.Invisible, nodes.label))]) - if ( self.compact_simple - or self.compact_field_list - or self.compact_p and parent_length == 1): + if (self.compact_simple + or self.compact_field_list + or self.compact_p and parent_length == 1): return True return False diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py index 649a190da..be93375f3 100644 --- a/docutils/docutils/writers/latex2e/__init__.py +++ b/docutils/docutils/writers/latex2e/__init__.py @@ -3054,7 +3054,7 @@ class LaTeXTranslator(nodes.NodeVisitor): pass _thead_depth = 0 - def thead_depth (self): + def thead_depth(self): return self._thead_depth def visit_thead(self, node): diff --git a/docutils/docutils/writers/odf_odt/__init__.py b/docutils/docutils/writers/odf_odt/__init__.py index 5fce817c8..7b3eb030c 100644 --- a/docutils/docutils/writers/odf_odt/__init__.py +++ b/docutils/docutils/writers/odf_odt/__init__.py @@ -2840,11 +2840,11 @@ class ODFTranslator(nodes.GenericNodeVisitor): self.in_paragraph = False self.set_to_parent() if self.in_header: - self.header_content.append( self.current_element[-1] ) - self.current_element.remove( self.current_element[-1] ) + self.header_content.append(self.current_element[-1]) + self.current_element.remove(self.current_element[-1]) elif self.in_footer: - self.footer_content.append( self.current_element[-1] ) - self.current_element.remove( self.current_element[-1] ) + self.footer_content.append(self.current_element[-1]) + self.current_element.remove(self.current_element[-1]) def visit_problematic(self, node): pass diff --git a/docutils/docutils/writers/odf_odt/pygmentsformatter.py b/docutils/docutils/writers/odf_odt/pygmentsformatter.py index 3dd13761b..f0668a221 100644 --- a/docutils/docutils/writers/odf_odt/pygmentsformatter.py +++ b/docutils/docutils/writers/odf_odt/pygmentsformatter.py @@ -19,7 +19,7 @@ class OdtPygmentsFormatter(pygments.formatter.Formatter): self.rststyle_function = rststyle_function self.escape_function = escape_function - def rststyle(self, name, parameters=( )): + def rststyle(self, name, parameters=()): return self.rststyle_function(name, parameters) diff --git a/docutils/docutils/writers/s5_html/__init__.py b/docutils/docutils/writers/s5_html/__init__.py index 2672ffc61..a93cc88c5 100644 --- a/docutils/docutils/writers/s5_html/__init__.py +++ b/docutils/docutils/writers/s5_html/__init__.py @@ -207,8 +207,8 @@ class S5HTMLTranslator(html4css1.HTMLTranslator): for f in os.listdir(path): # copy all files from each theme if f == self.base_theme_file: continue # ... except the "__base__" file - if ( self.copy_file(f, path, dest) - and f in self.required_theme_files): + if (self.copy_file(f, path, dest) + and f in self.required_theme_files): required_files_copied[f] = 1 if default: break # "default" theme has no base theme diff --git a/docutils/test/test_parsers/test_rst/test_tables.py b/docutils/test/test_parsers/test_rst/test_tables.py index be742509c..c4c3ffdb2 100755 --- a/docutils/test/test_parsers/test_rst/test_tables.py +++ b/docutils/test/test_parsers/test_rst/test_tables.py @@ -571,7 +571,7 @@ 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] +""") % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70] # noqa: E203 for part in range(len(include2) // 70 + 1))), """\ <document source="test data"> @@ -606,7 +606,7 @@ Something before. Something afterwards. And more. -""") % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70] +""") % ('\n'.join('| %-70s |' % include2[part * 70 : (part + 1) * 70] # noqa: E203 for part in range(len(include2) // 70 + 1))), """\ <document source="test data"> @@ -1274,7 +1274,7 @@ 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] +""" % ('\n'.join(' %-65s' % include2[part * 65 : (part + 1) * 65] # noqa: E203 for part in range(len(include2) // 65 + 1))), """\ <document source="test data"> diff --git a/docutils/test/test_settings.py b/docutils/test/test_settings.py index ac6fcd52f..cdfbc1cb1 100755 --- a/docutils/test/test_settings.py +++ b/docutils/test/test_settings.py @@ -272,15 +272,15 @@ class HelperFunctionsTests(unittest.TestCase): self.assertEqual(pathdict['spam'], 'spam') boolean_settings = ( - (True, True ), - ('1', True ), - ('on', True ), - ('yes', True ), - ('true', True ), - ('0', False ), - ('off', False ), - ('no', False ), - ('false', False ), + (True, True), + ('1', True), + ('on', True), + ('yes', True), + ('true', True), + ('0', False), + ('off', False), + ('no', False), + ('false', False), ) def test_validate_boolean(self): for t in self.boolean_settings: @@ -300,10 +300,10 @@ class HelperFunctionsTests(unittest.TestCase): def test_validate_colon_separated_string_list(self): tests = ( - ('a', ['a',] ), - ('a:b', ['a', 'b'] ), - (['a',], ['a',] ), - (['a', 'b:c'], ['a', 'b', 'c'] ), + ('a', ['a',]), + ('a:b', ['a', 'b']), + (['a',], ['a',]), + (['a', 'b:c'], ['a', 'b', 'c']), ) for t in tests: self.assertEqual( @@ -312,10 +312,10 @@ class HelperFunctionsTests(unittest.TestCase): def test_validate_comma_separated_list(self): tests = ( - ('a', ['a',] ), - ('a,b', ['a', 'b'] ), - (['a',], ['a',] ), - (['a', 'b,c'], ['a', 'b', 'c'] ), + ('a', ['a',]), + ('a,b', ['a', 'b']), + (['a',], ['a',]), + (['a', 'b,c'], ['a', 'b', 'c']), ) for t in tests: self.assertEqual( @@ -324,10 +324,10 @@ class HelperFunctionsTests(unittest.TestCase): def test_validate_url_trailing_slash(self): tests = ( - ('', './' ), - (None, './' ), - ('http://example.org', 'http://example.org/' ), - ('http://example.org/', 'http://example.org/' ), + ('', './'), + (None, './'), + ('http://example.org', 'http://example.org/'), + ('http://example.org/', 'http://example.org/'), ) for t in tests: self.assertEqual( diff --git a/docutils/test/test_transforms/test_doctitle.py b/docutils/test/test_transforms/test_doctitle.py index a09f1d549..02cc9e49c 100755 --- a/docutils/test/test_transforms/test_doctitle.py +++ b/docutils/test/test_transforms/test_doctitle.py @@ -21,7 +21,7 @@ class AddNameToDocumentTitle(Directive): required_arguments = 0 optional_arguments = 0 final_argument_whitespace = True - option_spec = { } + option_spec = {} has_content = False def run(self): diff --git a/docutils/test/test_writers/test_html4css1_parts.py b/docutils/test/test_writers/test_html4css1_parts.py index c6250d57b..b04afac3e 100755 --- a/docutils/test/test_writers/test_html4css1_parts.py +++ b/docutils/test/test_writers/test_html4css1_parts.py @@ -197,7 +197,7 @@ Some stuff """] ]) -totest['No title promotion'] = ({'doctitle_xform' : 0, +totest['No title promotion'] = ({'doctitle_xform': 0, 'stylesheet_path': '', 'embed_stylesheet': 0}, [ ["""\ diff --git a/docutils/test/test_writers/test_html5_polyglot_parts.py b/docutils/test/test_writers/test_html5_polyglot_parts.py index b36254a39..16e3d233c 100644 --- a/docutils/test/test_writers/test_html5_polyglot_parts.py +++ b/docutils/test/test_writers/test_html5_polyglot_parts.py @@ -205,7 +205,7 @@ Some stuff """] ]) -totest['No title promotion'] = ({'doctitle_xform' : 0, +totest['No title promotion'] = ({'doctitle_xform': 0, 'stylesheet_path': '', 'embed_stylesheet': 0}, [ ["""\ diff --git a/docutils/tools/quicktest.py b/docutils/tools/quicktest.py index 3dd85d3f9..2c423f48e 100755 --- a/docutils/tools/quicktest.py +++ b/docutils/tools/quicktest.py @@ -96,7 +96,7 @@ def _test(input, document, optargs): %s %s], ] -""" % ( tq, escape(input.rstrip()), tq, tq, escape(output.rstrip()), tq ) +""" % (tq, escape(input.rstrip()), tq, tq, escape(output.rstrip()), tq) def escape(text): """ @@ -111,7 +111,7 @@ _outputFormatters = { 'rawxml': _rawxml, 'styledxml': _styledxml, 'xml': _prettyxml, - 'pretty' : _pretty, + 'pretty': _pretty, 'test': _test} def format(outputFormat, input, document, optargs): diff --git a/docutils/tools/test/test_buildhtml.py b/docutils/tools/test/test_buildhtml.py index 808d02720..ef7017e82 100644 --- a/docutils/tools/test/test_buildhtml.py +++ b/docutils/tools/test/test_buildhtml.py @@ -57,19 +57,19 @@ def process_and_return_filelist(options): return dirs, files class BuildHtmlTests(unittest.TestCase): - tree = ( "_tmp_test_tree", - "_tmp_test_tree/one.txt", - "_tmp_test_tree/two.txt", - "_tmp_test_tree/dir1", - "_tmp_test_tree/dir1/one.txt", - "_tmp_test_tree/dir1/two.txt", - "_tmp_test_tree/dir2", - "_tmp_test_tree/dir2/one.txt", - "_tmp_test_tree/dir2/two.txt", - "_tmp_test_tree/dir2/sub", - "_tmp_test_tree/dir2/sub/one.txt", - "_tmp_test_tree/dir2/sub/two.txt", - ) + tree = ("_tmp_test_tree", + "_tmp_test_tree/one.txt", + "_tmp_test_tree/two.txt", + "_tmp_test_tree/dir1", + "_tmp_test_tree/dir1/one.txt", + "_tmp_test_tree/dir1/two.txt", + "_tmp_test_tree/dir2", + "_tmp_test_tree/dir2/one.txt", + "_tmp_test_tree/dir2/two.txt", + "_tmp_test_tree/dir2/sub", + "_tmp_test_tree/dir2/sub/one.txt", + "_tmp_test_tree/dir2/sub/two.txt", + ) def setUp(self): self.root = tempfile.mkdtemp() @@ -94,14 +94,14 @@ class BuildHtmlTests(unittest.TestCase): def test_1(self): opts = ["--dry-run", self.root] - dirs, files = process_and_return_filelist( opts ) + dirs, files = process_and_return_filelist(opts) self.assertEqual(files.count("one.txt"), 4) def test_local(self): opts = ["--dry-run", "--local", self.root] - dirs, files = process_and_return_filelist( opts ) - self.assertEqual( len(dirs), 1) - self.assertEqual( files, []) + dirs, files = process_and_return_filelist(opts) + self.assertEqual(len(dirs), 1) + self.assertEqual(files, []) if __name__ == '__main__': unittest.main() diff --git a/docutils/tox.ini b/docutils/tox.ini index eea37e2af..fb36dc478 100644 --- a/docutils/tox.ini +++ b/docutils/tox.ini @@ -31,10 +31,6 @@ ignore = E129, # visually indented line with same indent as next logical line # allowed by PEP8 - E201, # whitespace after '(' - E202, # whitespace before '}' - E203, # whitespace before ':' - E211, # whitespace before '(' E221, # multiple spaces before operator E222, # multiple spaces after operator E225, # missing whitespace around operator |
