From 109f461ae4bffc3870080e85a14da403a039effe Mon Sep 17 00:00:00 2001 From: milde Date: Fri, 4 Mar 2022 15:55:26 +0000 Subject: Fix (some) missing blank lines flake8 rules E301: expected 1 blank line, found 0 E306: expected 1 blank line before a nested definition, found 0 git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9024 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/docutils/nodes.py | 2 +- docutils/docutils/utils/math/latex2mathml.py | 2 ++ docutils/docutils/writers/docutils_xml.py | 1 - docutils/docutils/writers/html4css1/__init__.py | 8 ++++---- docutils/docutils/writers/html5_polyglot/__init__.py | 7 +++++-- docutils/docutils/writers/latex2e/__init__.py | 1 + docutils/docutils/writers/manpage.py | 6 ++++++ docutils/test/test_settings.py | 1 + docutils/test/test_statemachine.py | 1 + docutils/test/test_writers/test_odt.py | 1 + docutils/tox.ini | 2 -- 11 files changed, 22 insertions(+), 10 deletions(-) (limited to 'docutils') diff --git a/docutils/docutils/nodes.py b/docutils/docutils/nodes.py index 2852e9ee3..c3c090ed3 100644 --- a/docutils/docutils/nodes.py +++ b/docutils/docutils/nodes.py @@ -283,10 +283,10 @@ class Node: # implementations that use only new-style classes, like PyPy). if isinstance(condition, type): node_class = condition + def condition(node, node_class=node_class): return isinstance(node, node_class) - if include_self and (condition is None or condition(self)): yield self if descend and len(self.children): diff --git a/docutils/docutils/utils/math/latex2mathml.py b/docutils/docutils/utils/math/latex2mathml.py index 2dc95b8fc..11c8544bc 100644 --- a/docutils/docutils/utils/math/latex2mathml.py +++ b/docutils/docutils/utils/math/latex2mathml.py @@ -363,8 +363,10 @@ class math: # see `docutils.nodes.Element` for dict/list interface def __getitem__(self, key): return self.attributes[key] + def __setitem__(self, key, item): self.attributes[key] = item + def get(self, *args, **kwargs): return self.attributes.get(*args, **kwargs) diff --git a/docutils/docutils/writers/docutils_xml.py b/docutils/docutils/writers/docutils_xml.py index fccdafa92..78acddd90 100644 --- a/docutils/docutils/writers/docutils_xml.py +++ b/docutils/docutils/writers/docutils_xml.py @@ -143,7 +143,6 @@ class XMLTranslator(nodes.GenericNodeVisitor): if not self.in_simple: self.output.append(self.newline) - # specific visit and depart methods # --------------------------------- diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index a05172e70..8cc09c601 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -215,7 +215,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): self.colspecs.append(node) # "stubs" list is an attribute of the tgroup element: node.parent.stubs.append(node.attributes.get('stub')) - # + def depart_colspec(self, node): # write out when all colspecs are processed if isinstance(node.next_node(descend=False, siblings=True), @@ -542,7 +542,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): # html4css1 strives for IE6 compatibility.) object_image_types = {'.svg': 'image/svg+xml', '.swf': 'application/x-shockwave-flash'} - # + def visit_image(self, node): atts = {} uri = node['uri'] @@ -864,7 +864,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): # hard-coded vertical alignment def visit_tbody(self, node): self.body.append(self.starttag(node, 'tbody', valign='top')) - # + def depart_tbody(self, node): self.body.append('\n') @@ -880,7 +880,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): # hard-coded vertical alignment def visit_thead(self, node): self.body.append(self.starttag(node, 'thead', valign='bottom')) - # + def depart_thead(self, node): self.body.append('\n') diff --git a/docutils/docutils/writers/html5_polyglot/__init__.py b/docutils/docutils/writers/html5_polyglot/__init__.py index 80be0ff27..132902bc9 100644 --- a/docutils/docutils/writers/html5_polyglot/__init__.py +++ b/docutils/docutils/writers/html5_polyglot/__init__.py @@ -158,6 +158,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): # use HTML block-level tags if matching class value found supported_block_tags = {'ins', 'del'} + def visit_container(self, node): # If there is exactly one of the "supported block tags" in # the list of class values, use it as tag name: @@ -175,7 +176,6 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): def depart_container(self, node): self.body.append('\n' % node.html5tagname) - # no standard meta tag name in HTML5, use dcterms.rights # see https://wiki.whatwg.org/wiki/MetaExtensions def visit_copyright(self, node): @@ -310,8 +310,9 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): supported_inline_tags = {'code', 'kbd', 'dfn', 'samp', 'var', 'bdi', 'del', 'ins', 'mark', 'small', 'b', 'i', 'q', 's', 'u'} + + # Use `supported_inline_tags` if found in class values def visit_inline(self, node): - # Use `supported_inline_tags` if found in class values classes = node['classes'] tags = [cls for cls in self.supported_inline_tags if cls in classes] @@ -389,12 +390,14 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): node['xml:lang'] = node['lang'] meta = self.emptytag(node, 'meta', **node.non_default_attributes()) self.add_meta(meta) + def depart_meta(self, node): pass # no standard meta tag name in HTML5 def visit_organization(self, node): self.visit_docinfo_item(node, 'organization', meta=False) + def depart_organization(self, node): self.depart_docinfo_item() diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py index 520284809..ad3fbe935 100644 --- a/docutils/docutils/writers/latex2e/__init__.py +++ b/docutils/docutils/writers/latex2e/__init__.py @@ -3057,6 +3057,7 @@ class LaTeXTranslator(nodes.NodeVisitor): pass _thead_depth = 0 + def thead_depth(self): return self._thead_depth diff --git a/docutils/docutils/writers/manpage.py b/docutils/docutils/writers/manpage.py index 40c7967ec..f1f570b92 100644 --- a/docutils/docutils/writers/manpage.py +++ b/docutils/docutils/writers/manpage.py @@ -113,11 +113,14 @@ class Table: self._options = ['center'] self._tab_char = '\t' self._coldefs = [] + def new_row(self): self._rows.append([]) + def append_separator(self, separator): """Append the separator for table head.""" self._rows.append([separator]) + def append_cell(self, cell_lines): """cell_lines is an array of lines""" start = 0 @@ -126,12 +129,14 @@ class Table: self._rows[-1].append(cell_lines[start:]) if len(self._coldefs) < len(self._rows[-1]): self._coldefs.append('l') + def _minimize_cell(self, cell_lines): """Remove leading and trailing blank and ``.sp`` lines""" while cell_lines and cell_lines[0] in ('\n', '.sp\n'): del cell_lines[0] while cell_lines and cell_lines[-1] in ('\n', '.sp\n'): del cell_lines[-1] + def as_list(self): text = ['.TS\n'] text.append(' '.join(self._options) + ';\n') @@ -349,6 +354,7 @@ class Translator(nodes.NodeVisitor): def get_width(self): return self._indent + def __repr__(self): return 'enum_style-%s' % list(self._style) diff --git a/docutils/test/test_settings.py b/docutils/test/test_settings.py index 0630eece8..b9f482aa7 100755 --- a/docutils/test/test_settings.py +++ b/docutils/test/test_settings.py @@ -282,6 +282,7 @@ class HelperFunctionsTests(unittest.TestCase): ('no', False), ('false', False), ) + def test_validate_boolean(self): for t in self.boolean_settings: self.assertEqual( diff --git a/docutils/test/test_statemachine.py b/docutils/test/test_statemachine.py index 4e2a9b723..7ad0111d4 100755 --- a/docutils/test/test_statemachine.py +++ b/docutils/test/test_statemachine.py @@ -271,6 +271,7 @@ class MiscTests(unittest.TestCase): s2l_string = "hello\tthere\thow are\tyou?\n\tI'm fine\tthanks.\n" s2l_expected = ['hello there how are you?', " I'm fine thanks."] + def test_string2lines(self): self.assertEqual(statemachine.string2lines(self.s2l_string), self.s2l_expected) diff --git a/docutils/test/test_writers/test_odt.py b/docutils/test/test_writers/test_odt.py index 508b76a1d..85d9f1d25 100755 --- a/docutils/test/test_writers/test_odt.py +++ b/docutils/test/test_writers/test_odt.py @@ -172,6 +172,7 @@ class DocutilsOdtTestCase(DocutilsTestSupport.StandardTestCase): def test_odt_footnotes(self): self.process_test('odt_footnotes.txt', 'odt_footnotes.odt', save_output_name='odt_footnotes.odt') + def test_odt_raw(self): self.process_test('odt_raw.txt', 'odt_raw.odt', save_output_name='odt_raw.odt') diff --git a/docutils/tox.ini b/docutils/tox.ini index 1a85149f3..3af8c3a66 100644 --- a/docutils/tox.ini +++ b/docutils/tox.ini @@ -38,11 +38,9 @@ ignore = # whitespace around the operators with the lowest priority(ies). # Use your own judgment; …" - E301, # expected 1 blank line, found 0 E302, # expected 2 blank lines, found 1 E303, # too many blank lines (N) E305, # expected 2 blank lines after class or function definition, found 1 - E306, # expected 1 blank line before a nested definition, found 0 E401, # multiple imports on one line E402, # module level import not at top of file E501, # line too long (N > 79 characters) -- cgit v1.2.1