summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-03-05 23:29:48 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-03-05 23:29:48 +0000
commit5d32cb4bd24a3bf8bb6ad7a3d2b9a8ac1573c55d (patch)
tree8babec14dec3fc2a2d025cf66d361df321d56d15
parent764a86d8fc5d1483fa366531b339a7a48fc93366 (diff)
downloaddocutils-5d32cb4bd24a3bf8bb6ad7a3d2b9a8ac1573c55d.tar.gz
Avoid line break after binary operator.
Breaking before binary operators is the recommended style in PEP 8 (changed in April 2016). flake8 rule W504 git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9035 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/docutils/core.py4
-rw-r--r--docutils/docutils/frontend.py4
-rw-r--r--docutils/docutils/io.py4
-rw-r--r--docutils/docutils/parsers/rst/directives/admonitions.py4
-rw-r--r--docutils/docutils/parsers/rst/states.py14
-rw-r--r--docutils/docutils/transforms/misc.py18
-rw-r--r--docutils/docutils/transforms/references.py6
-rw-r--r--docutils/docutils/utils/error_reporting.py8
-rw-r--r--docutils/docutils/writers/_html_base.py16
-rw-r--r--docutils/docutils/writers/html4css1/__init__.py45
-rw-r--r--docutils/docutils/writers/html5_polyglot/__init__.py6
-rw-r--r--docutils/docutils/writers/latex2e/__init__.py57
-rw-r--r--docutils/docutils/writers/odf_odt/__init__.py40
-rw-r--r--docutils/test/DocutilsTestSupport.py6
-rw-r--r--docutils/test/package_unittest.py19
-rwxr-xr-xdocutils/test/test_writers/test_latex2e.py5
-rw-r--r--docutils/test/test_writers/test_manpage.py33
-rwxr-xr-xdocutils/tools/quicktest.py4
-rw-r--r--docutils/tox.ini3
19 files changed, 141 insertions, 155 deletions
diff --git a/docutils/docutils/core.py b/docutils/docutils/core.py
index 1a7d20c84..67d749ce8 100644
--- a/docutils/docutils/core.py
+++ b/docutils/docutils/core.py
@@ -273,8 +273,8 @@ Please report errors to <docutils-users@lists.sourceforge.net>.
Include "--traceback" output, Docutils version (%s%s),
Python version (%s), your OS type & version, and the
command line used.""" % (__version__,
- docutils.__version_details__ and
- ' [%s]'%docutils.__version_details__ or '',
+ docutils.__version_details__
+ and ' [%s]'%docutils.__version_details__ or '',
sys.version.split()[0])), file=self._stderr)
def report_SystemMessage(self, error):
diff --git a/docutils/docutils/frontend.py b/docutils/docutils/frontend.py
index a80c1c581..c61e2b56c 100644
--- a/docutils/docutils/frontend.py
+++ b/docutils/docutils/frontend.py
@@ -596,8 +596,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
version_template = ('%%prog (Docutils %s%s, Python %s, on %s)'
% (docutils.__version__,
- docutils.__version_details__ and
- ' [%s]'%docutils.__version_details__ or '',
+ docutils.__version_details__
+ and ' [%s]'%docutils.__version_details__ or '',
sys.version.split()[0], sys.platform))
"""Default version message."""
diff --git a/docutils/docutils/io.py b/docutils/docutils/io.py
index 8b62d044c..812af3a24 100644
--- a/docutils/docutils/io.py
+++ b/docutils/docutils/io.py
@@ -254,8 +254,8 @@ class ErrorOutput:
self.destination = destination
"""Where warning output is sent."""
- self.encoding = (encoding or getattr(destination, 'encoding', None) or
- locale_encoding or 'ascii')
+ self.encoding = (encoding or getattr(destination, 'encoding', None)
+ or locale_encoding or 'ascii')
"""The output character encoding."""
self.encoding_errors = encoding_errors
diff --git a/docutils/docutils/parsers/rst/directives/admonitions.py b/docutils/docutils/parsers/rst/directives/admonitions.py
index 8d04f4f2d..60ac3abe3 100644
--- a/docutils/docutils/parsers/rst/directives/admonitions.py
+++ b/docutils/docutils/parsers/rst/directives/admonitions.py
@@ -41,8 +41,8 @@ class BaseAdmonition(Directive):
admonition_node += title
admonition_node += messages
if 'classes' not in self.options:
- admonition_node['classes'] += ['admonition-' +
- nodes.make_id(title_text)]
+ admonition_node['classes'] += ['admonition-'
+ + nodes.make_id(title_text)]
self.state.nested_parse(self.content, self.content_offset,
admonition_node)
return [admonition_node]
diff --git a/docutils/docutils/parsers/rst/states.py b/docutils/docutils/parsers/rst/states.py
index 63a1e029e..a75fb324a 100644
--- a/docutils/docutils/parsers/rst/states.py
+++ b/docutils/docutils/parsers/rst/states.py
@@ -1043,8 +1043,8 @@ class Inliner:
# Must recurse on strings before *and* after the match;
# there may be multiple patterns.
return (self.implicit_inline(text[:match.start()], lineno)
- + method(match, lineno) +
- self.implicit_inline(text[match.end():], lineno))
+ + method(match, lineno)
+ + self.implicit_inline(text[match.end():], lineno))
except MarkupMismatch:
pass
return [nodes.Text(text)]
@@ -2062,8 +2062,8 @@ class Body(RSTState):
initial_state='SubstitutionDef', blank_finish=blank_finish)
i = 0
for node in substitution_node[:]:
- if not (isinstance(node, nodes.Inline) or
- isinstance(node, nodes.Text)):
+ if not (isinstance(node, nodes.Inline)
+ or isinstance(node, nodes.Text)):
self.parent += substitution_node[i]
del substitution_node[i]
else:
@@ -2088,9 +2088,9 @@ class Body(RSTState):
return [substitution_node], blank_finish
def disallowed_inside_substitution_definitions(self, node):
- if (node['ids'] or
- isinstance(node, nodes.reference) and node.get('anonymous') or
- isinstance(node, nodes.footnote_reference) and node.get('auto')):
+ if (node['ids']
+ or isinstance(node, nodes.reference) and node.get('anonymous')
+ or isinstance(node, nodes.footnote_reference) and node.get('auto')): # noqa: E501
return True
else:
return False
diff --git a/docutils/docutils/transforms/misc.py b/docutils/docutils/transforms/misc.py
index b17033d79..29e2f8fdc 100644
--- a/docutils/docutils/transforms/misc.py
+++ b/docutils/docutils/transforms/misc.py
@@ -49,8 +49,8 @@ class ClassAttribute(Transform):
# Check for appropriate following siblings:
for index in range(parent.index(child) + 1, len(parent)):
element = parent[index]
- if (isinstance(element, nodes.Invisible) or
- isinstance(element, nodes.system_message)):
+ if (isinstance(element, nodes.Invisible)
+ or isinstance(element, nodes.system_message)):
continue
element['classes'] += pending.details['class']
pending.parent.remove(pending)
@@ -100,13 +100,13 @@ class Transitions(Transform):
def visit_transition(self, node):
index = node.parent.index(node)
error = None
- if (index == 0 or
- isinstance(node.parent[0], nodes.title) and
- (index == 1 or
- isinstance(node.parent[1], nodes.subtitle) and
- index == 2)):
- assert (isinstance(node.parent, nodes.document) or
- isinstance(node.parent, nodes.section))
+ if (index == 0
+ or isinstance(node.parent[0], nodes.title)
+ and (index == 1
+ or isinstance(node.parent[1], nodes.subtitle)
+ and index == 2)):
+ assert (isinstance(node.parent, nodes.document)
+ or isinstance(node.parent, nodes.section))
error = self.document.reporter.error(
'Document or section may not begin with a transition.',
source=node.source, line=node.line)
diff --git a/docutils/docutils/transforms/references.py b/docutils/docutils/transforms/references.py
index cb1855ca3..e2f743d73 100644
--- a/docutils/docutils/transforms/references.py
+++ b/docutils/docutils/transforms/references.py
@@ -40,9 +40,9 @@ class PropagateTargets(Transform):
def apply(self):
for target in self.document.findall(nodes.target):
# Only block-level targets without reference (like ".. _target:"):
- if (isinstance(target.parent, nodes.TextElement) or
- (target.hasattr('refid') or target.hasattr('refuri') or
- target.hasattr('refname'))):
+ if (isinstance(target.parent, nodes.TextElement)
+ or (target.hasattr('refid') or target.hasattr('refuri')
+ or target.hasattr('refname'))):
continue
assert len(target) == 0, 'error: block-level target has children'
next_node = target.next_node(ascend=True)
diff --git a/docutils/docutils/utils/error_reporting.py b/docutils/docutils/utils/error_reporting.py
index 3226290e2..3d400697b 100644
--- a/docutils/docutils/utils/error_reporting.py
+++ b/docutils/docutils/utils/error_reporting.py
@@ -92,8 +92,8 @@ class SafeString:
def __init__(self, data, encoding=None, encoding_errors='backslashreplace',
decoding_errors='replace'):
self.data = data
- self.encoding = (encoding or getattr(data, 'encoding', None) or
- locale_encoding or 'ascii')
+ self.encoding = (encoding or getattr(data, 'encoding', None)
+ or locale_encoding or 'ascii')
self.encoding_errors = encoding_errors
self.decoding_errors = decoding_errors
@@ -195,8 +195,8 @@ class ErrorOutput:
self.stream = stream
"""Where warning output is sent."""
- self.encoding = (encoding or getattr(stream, 'encoding', None) or
- locale_encoding or 'ascii')
+ self.encoding = (encoding or getattr(stream, 'encoding', None)
+ or locale_encoding or 'ascii')
"""The output character encoding."""
self.encoding_errors = encoding_errors
diff --git a/docutils/docutils/writers/_html_base.py b/docutils/docutils/writers/_html_base.py
index 31dfceea7..58479fb1b 100644
--- a/docutils/docutils/writers/_html_base.py
+++ b/docutils/docutils/writers/_html_base.py
@@ -1032,9 +1032,9 @@ class HTMLTranslator(nodes.NodeVisitor):
del atts[att_name]
if style:
atts['style'] = ' '.join(style)
- if (isinstance(node.parent, nodes.TextElement) or
- (isinstance(node.parent, nodes.reference) and
- not isinstance(node.parent.parent, nodes.TextElement))):
+ if (isinstance(node.parent, nodes.TextElement)
+ or (isinstance(node.parent, nodes.reference)
+ and not isinstance(node.parent.parent, nodes.TextElement))):
# Inline context or surrounded by <a>...</a>.
suffix = ''
else:
@@ -1383,8 +1383,8 @@ class HTMLTranslator(nodes.NodeVisitor):
def depart_paragraph(self, node):
self.body.append('</p>')
- if not (isinstance(node.parent, (nodes.list_item, nodes.entry)) and
- (len(node.parent) == 1)):
+ if not (isinstance(node.parent, (nodes.list_item, nodes.entry))
+ and (len(node.parent) == 1)):
self.body.append('\n')
def visit_problematic(self, node):
@@ -1722,9 +1722,9 @@ class SimpleListChecker(nodes.GenericNodeVisitor):
children = [child for child in node.children
if not isinstance(child, nodes.Invisible)]
if (children and isinstance(children[0], nodes.paragraph)
- and (isinstance(children[-1], nodes.bullet_list) or
- isinstance(children[-1], nodes.enumerated_list) or
- isinstance(children[-1], nodes.field_list))):
+ and (isinstance(children[-1], nodes.bullet_list)
+ or isinstance(children[-1], nodes.enumerated_list)
+ or isinstance(children[-1], nodes.field_list))):
children.pop()
if len(children) <= 1:
return
diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py
index 1ea84bb33..d69ad21e4 100644
--- a/docutils/docutils/writers/html4css1/__init__.py
+++ b/docutils/docutils/writers/html4css1/__init__.py
@@ -222,9 +222,9 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
if isinstance(node.next_node(descend=False, siblings=True),
nodes.colspec):
return
- if 'colwidths-auto' in node.parent.parent['classes'] or (
- 'colwidths-auto' in self.settings.table_style and
- ('colwidths-given' not in node.parent.parent['classes'])):
+ if ('colwidths-auto' in node.parent.parent['classes']
+ or ('colwidths-auto' in self.settings.table_style
+ and 'colwidths-given' not in node.parent.parent['classes'])):
return
total_width = sum(node['colwidth'] for node in self.colspecs)
self.body.append(self.starttag(node, 'colgroup'))
@@ -411,9 +411,9 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
self.body.append(self.starttag(node, 'td', '', CLASS='field-body'))
self.set_class_on_child(node, 'first', 0)
field = node.parent
- if (self.compact_field_list or
- isinstance(field.parent, nodes.docinfo) or
- field.parent.index(field) == len(field.parent) - 1):
+ if (self.compact_field_list
+ or isinstance(field.parent, nodes.docinfo)
+ or field.parent.index(field) == len(field.parent) - 1):
# If we are in a compact list, the docinfo, or if this is
# the last field of the field list, do not add vertical
# space after last element.
@@ -436,10 +436,10 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
assert isinstance(field_body, nodes.field_body)
children = [n for n in field_body
if not isinstance(n, nodes.Invisible)]
- if not (len(children) == 0 or
- len(children) == 1 and
- isinstance(children[0],
- (nodes.paragraph, nodes.line_block))):
+ if not (len(children) == 0
+ or len(children) == 1
+ and isinstance(children[0],
+ (nodes.paragraph, nodes.line_block))):
self.compact_field_list = False
break
self.body.append(self.starttag(node, 'table', frame='void',
@@ -592,9 +592,9 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
del atts[att_name]
if style:
atts['style'] = ' '.join(style)
- if (isinstance(node.parent, nodes.TextElement) or
- (isinstance(node.parent, nodes.reference) and
- not isinstance(node.parent.parent, nodes.TextElement))):
+ if (isinstance(node.parent, nodes.TextElement)
+ or (isinstance(node.parent, nodes.reference)
+ and not isinstance(node.parent.parent, nodes.TextElement))):
# Inline context or surrounded by <a>...</a>.
suffix = ''
else:
@@ -603,8 +603,8 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
atts['class'] = 'align-%s' % node['align']
if ext in self.object_image_types:
# do NOT use an empty tag: incorrect rendering in browsers
- self.body.append(self.starttag(node, 'object', '', **atts) +
- node.get('alt', uri) + '</object>' + suffix)
+ self.body.append(self.starttag(node, 'object', '', **atts)
+ + node.get('alt', uri) + '</object>' + suffix)
else:
self.body.append(self.emptytag(node, 'img', suffix, **atts))
@@ -714,14 +714,15 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
"""
Determine if the <p> tags around paragraph ``node`` can be omitted.
"""
- if (isinstance(node.parent, nodes.document) or
- isinstance(node.parent, nodes.compound)):
+ if (isinstance(node.parent, nodes.document)
+ or isinstance(node.parent, nodes.compound)):
# Never compact paragraphs in document or compound.
return False
for key, value in node.attlist():
- if (node.is_not_default(key) and
- not (key == 'classes' and value in
- ([], ['first'], ['last'], ['first', 'last']))):
+ if (node.is_not_default(key)
+ and not (key == 'classes'
+ and value in ([], ['first'],
+ ['last'], ['first', 'last']))):
# Attribute which needs to survive.
return False
first = isinstance(node.parent[0], nodes.label) # skip label
@@ -788,8 +789,8 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
elif isinstance(node.parent, nodes.section):
tag = 'h%s' % (self.section_level + self.initial_header_level - 1)
self.body.append(
- self.starttag(node, tag, '', CLASS='section-subtitle') +
- self.starttag({}, 'span', '', CLASS='section-subtitle'))
+ self.starttag(node, tag, '', CLASS='section-subtitle')
+ + self.starttag({}, 'span', '', CLASS='section-subtitle'))
self.context.append('</span></%s>\n' % tag)
def depart_subtitle(self, node):
diff --git a/docutils/docutils/writers/html5_polyglot/__init__.py b/docutils/docutils/writers/html5_polyglot/__init__.py
index 8602cdf6b..48a24cb6d 100644
--- a/docutils/docutils/writers/html5_polyglot/__init__.py
+++ b/docutils/docutils/writers/html5_polyglot/__init__.py
@@ -290,9 +290,9 @@ class HTMLTranslator(writers._html_base.HTMLTranslator):
if getattr(self.settings, 'image_loading', None) == 'lazy':
atts['loading'] = 'lazy'
# No newline in inline context or if surrounded by <a>...</a>.
- if (isinstance(node.parent, nodes.TextElement) or
- (isinstance(node.parent, nodes.reference) and
- not isinstance(node.parent.parent, nodes.TextElement))):
+ if (isinstance(node.parent, nodes.TextElement)
+ or (isinstance(node.parent, nodes.reference)
+ and not isinstance(node.parent.parent, nodes.TextElement))):
suffix = ''
else:
suffix = '\n'
diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py
index 7308d020d..bf43c62e5 100644
--- a/docutils/docutils/writers/latex2e/__init__.py
+++ b/docutils/docutils/writers/latex2e/__init__.py
@@ -445,8 +445,8 @@ class Babel:
self.setup.extend([r'\makeatletter',
r' \addto\extrasbasque{\bbl@deactivate{~}}',
r'\makeatother'])
- if (languages[-1] == 'english' and
- 'french' in self.otherlanguages.keys()):
+ if (languages[-1] == 'english'
+ and 'french' in self.otherlanguages.keys()):
self.setup += ['% Prevent side-effects if French hyphenation '
'patterns are not loaded:',
r'\frenchbsetup{StandardLayout}',
@@ -1323,9 +1323,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.requirements['_textquotedbl'] = (
r'\DeclareTextSymbolDefault{\textquotedbl}{T1}')
# page layout with typearea (if there are relevant document options)
- if (settings.documentclass.find('scr') == -1 and
- (self.documentoptions.find('DIV') != -1 or
- self.documentoptions.find('BCOR') != -1)):
+ if (settings.documentclass.find('scr') == -1
+ and (self.documentoptions.find('DIV') != -1
+ or self.documentoptions.find('BCOR') != -1)):
self.requirements['typearea'] = r'\usepackage{typearea}'
# Stylesheets
@@ -1382,8 +1382,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
r'\setcounter{secnumdepth}{%d}'
% self.d_class.latex_section_depth(secnumdepth))
# start with specified number:
- if (hasattr(settings, 'sectnum_start') and
- settings.sectnum_start != 1):
+ if (hasattr(settings, 'sectnum_start')
+ and settings.sectnum_start != 1):
self.requirements['sectnum_start'] = (
r'\setcounter{%s}{%d}' % (self.d_class.sections[0],
settings.sectnum_start-1))
@@ -1995,8 +1995,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_document(self, node):
# titled document?
- if (self.use_latex_docinfo or len(node) and
- isinstance(node[0], nodes.title)):
+ if (self.use_latex_docinfo or len(node)
+ and isinstance(node[0], nodes.title)):
protect = (self.settings.documentclass == 'memoir')
self.title_labels += self.ids_to_labels(node, set_anchor=False,
protect=protect)
@@ -2004,8 +2004,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
def depart_document(self, node):
# Complete header with information gained from walkabout
# * language setup
- if (self.babel.otherlanguages or
- self.babel.language not in ('', 'english')):
+ if (self.babel.otherlanguages
+ or self.babel.language not in ('', 'english')):
self.requirements['babel'] = self.babel()
# * conditional requirements (before style sheet)
self.requirements = self.requirements.sortedvalues()
@@ -2434,11 +2434,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
if 'width' in attrs:
include_graphics_options.append(
'width=%s' % self.to_latex_length(attrs['width']))
- if not (self.is_inline(node) or
- isinstance(node.parent, (nodes.figure, nodes.compound))):
+ if not (self.is_inline(node)
+ or isinstance(node.parent, (nodes.figure, nodes.compound))):
pre.append('\n')
- if not (self.is_inline(node) or
- isinstance(node.parent, nodes.figure)):
+ if not (self.is_inline(node)
+ or isinstance(node.parent, nodes.figure)):
post.append('\n')
pre.reverse()
self.out.extend(pre)
@@ -2506,8 +2506,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_literal(self, node):
self.literal = True
- if ('code' in node['classes'] and
- self.settings.syntax_highlight != 'none'):
+ if ('code' in node['classes']
+ and self.settings.syntax_highlight != 'none'):
self.requirements['color'] = PreambleCmds.color
if not self.fallback_stylesheet:
self.fallbacks['code'] = PreambleCmds.highlight_rules
@@ -2980,10 +2980,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.active_table = Table(self, 'tabular')
# A longtable moves before \paragraph and \subparagraph
# section titles if it immediately follows them:
- if (self.active_table._latex_type == 'longtable' and
- isinstance(node.parent, nodes.section) and
- node.parent.index(node) == 1 and
- self.d_class.section(self.section_level).find('paragraph') != -1):
+ if (self.active_table._latex_type == 'longtable'
+ and isinstance(node.parent, nodes.section)
+ and node.parent.index(node) == 1
+ and self.d_class.section(
+ self.section_level).find('paragraph') != -1):
self.out.append('\\leavevmode')
self.active_table.open()
self.active_table.set_table_style(node, self.settings)
@@ -3090,9 +3091,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.pdfinfo.append(' pdftitle={%s},' %
self.encode(node.astext()))
# Topic titles (topic, admonition, sidebar)
- elif (isinstance(node.parent, nodes.topic) or
- isinstance(node.parent, nodes.admonition) or
- isinstance(node.parent, nodes.sidebar)):
+ elif (isinstance(node.parent, nodes.topic)
+ or isinstance(node.parent, nodes.admonition)
+ or isinstance(node.parent, nodes.sidebar)):
classes = node.parent['classes'] or [node.parent.tagname]
if self.settings.legacy_class_functions:
self.fallbacks['title'] = PreambleCmds.title_legacy
@@ -3235,8 +3236,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
# table of contents:
if 'contents' in node['classes']:
self.visit_contents(node)
- elif ('abstract' in node['classes'] and
- self.settings.use_latex_abstract):
+ elif ('abstract' in node['classes']
+ and self.settings.use_latex_abstract):
self.push_output_collector(self.abstract)
self.out.append('\\begin{abstract}')
if isinstance(node.next_node(), nodes.title):
@@ -3265,8 +3266,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.duclass_close(node)
else:
self.depart_block_quote(node)
- if ('abstract' in node['classes'] or
- 'dedication' in node['classes']):
+ if ('abstract' in node['classes']
+ or 'dedication' in node['classes']):
self.pop_output_collector()
def visit_transition(self, node):
diff --git a/docutils/docutils/writers/odf_odt/__init__.py b/docutils/docutils/writers/odf_odt/__init__.py
index aab578d5b..4e0f71870 100644
--- a/docutils/docutils/writers/odf_odt/__init__.py
+++ b/docutils/docutils/writers/odf_odt/__init__.py
@@ -1008,9 +1008,7 @@ class ODFTranslator(nodes.GenericNodeVisitor):
def find_first_text_p(self, el):
"""Search the generated doc and return the first <text:p> element.
"""
- if (
- el.tag == 'text:p' or
- el.tag == 'text:h'):
+ if el.tag == 'text:p' or el.tag == 'text:h':
return el
else:
for child in el:
@@ -1053,10 +1051,10 @@ class ODFTranslator(nodes.GenericNodeVisitor):
def setup_page(self):
self.setup_paper(self.dom_stylesheet)
- if (len(self.header_content) > 0 or
- len(self.footer_content) > 0 or
- self.settings.custom_header or
- self.settings.custom_footer):
+ if (len(self.header_content) > 0
+ or len(self.footer_content) > 0
+ or self.settings.custom_header
+ or self.settings.custom_footer):
self.add_header_footer(self.dom_stylesheet)
return etree.tostring(self.dom_stylesheet)
@@ -2318,9 +2316,9 @@ class ODFTranslator(nodes.GenericNodeVisitor):
margin_right = node.get(
'{urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0}'
'margin-right')
- if (page_width is None or
- margin_left is None or
- margin_right is None):
+ if (page_width is None
+ or margin_left is None
+ or margin_right is None):
continue
try:
page_width, _ = self.convert_to_cm(page_width)
@@ -2882,9 +2880,8 @@ class ODFTranslator(nodes.GenericNodeVisitor):
if self.settings.create_links:
if 'refuri' in node:
href = node['refuri']
- if (
- self.settings.cloak_email_addresses and
- href.startswith('mailto:')):
+ if (self.settings.cloak_email_addresses
+ and href.startswith('mailto:')):
href = self.cloak_mailto(href)
el = self.append_child('text:a', attrib={
'xlink:href': '%s' % href,
@@ -2901,10 +2898,9 @@ class ODFTranslator(nodes.GenericNodeVisitor):
else:
self.document.reporter.warning(
'References must have "refuri" or "refid" attribute.')
- if (
- self.in_table_of_contents and
- len(node.children) >= 1 and
- isinstance(node.children[0], docutils.nodes.generated)):
+ if (self.in_table_of_contents
+ and len(node.children) >= 1
+ and isinstance(node.children[0], docutils.nodes.generated)):
node.remove(node.children[0])
def depart_reference(self, node):
@@ -3198,9 +3194,8 @@ class ODFTranslator(nodes.GenericNodeVisitor):
self.set_current_element(el1)
def depart_title(self, node):
- if (
- isinstance(node.parent, docutils.nodes.section) or
- isinstance(node.parent, docutils.nodes.document)):
+ if (isinstance(node.parent, docutils.nodes.section)
+ or isinstance(node.parent, docutils.nodes.document)):
self.set_to_parent()
def visit_subtitle(self, node, move_ids=1):
@@ -3333,9 +3328,8 @@ class ODFTranslator(nodes.GenericNodeVisitor):
def update_toc_add_numbers(self, collection):
for level, el1 in collection:
- if (
- el1.tag == 'text:p' and
- el1.text != 'Table of Contents'):
+ if (el1.tag == 'text:p'
+ and el1.text != 'Table of Contents'):
el2 = SubElement(el1, 'text:tab')
el2.tail = '9999'
diff --git a/docutils/test/DocutilsTestSupport.py b/docutils/test/DocutilsTestSupport.py
index 51d6227ef..19472e275 100644
--- a/docutils/test/DocutilsTestSupport.py
+++ b/docutils/test/DocutilsTestSupport.py
@@ -852,9 +852,9 @@ def _format_str(*args):
assert quote_char in ("'", '"'), quote_char
assert r[0] == r[-1]
r = r[1:-1]
- r = (stripped + 3 * quote_char + '\\\n' +
- re.sub(r'(?<!\\)((\\\\)*)\\n', r'\1\n', r) +
- 3 * quote_char)
+ r = (stripped + 3*quote_char + '\\\n'
+ + re.sub(r'(?<!\\)((\\\\)*)\\n', r'\1\n', r)
+ + 3*quote_char)
r = re.sub(r' \n', r' \\n\\\n', r)
return_tuple.append(r)
return tuple(return_tuple)
diff --git a/docutils/test/package_unittest.py b/docutils/test/package_unittest.py
index 66f42bb67..9f81386a8 100644
--- a/docutils/test/package_unittest.py
+++ b/docutils/test/package_unittest.py
@@ -86,15 +86,16 @@ def loadTestModules(path, name='', packages=None):
p = paths.pop(0)
files = os.listdir(p)
for filename in files:
- if filename.startswith(name):
- fullpath = os.path.join(p, filename)
- if filename.endswith('.py'):
- fullpath = fullpath[len(path)+1:]
- testModules.append(path2mod(fullpath))
- elif (packages and os.path.isdir(fullpath) and
- os.path.isfile(os.path.join(fullpath, '__init__.py'))):
- paths.append(fullpath)
- # Import modules and add their tests to the suite.
+ if not filename.startswith(name):
+ continue
+ fullpath = os.path.join(p, filename)
+ if filename.endswith('.py'):
+ fullpath = fullpath[len(path)+1:]
+ testModules.append(path2mod(fullpath))
+ elif (packages and os.path.isdir(fullpath)
+ and os.path.isfile(os.path.join(fullpath, '__init__.py'))):
+ paths.append(fullpath)
+# Import modules and add their tests to the suite.
sys.path.insert(0, path)
for mod in testModules:
if debug:
diff --git a/docutils/test/test_writers/test_latex2e.py b/docutils/test/test_writers/test_latex2e.py
index ee0534f80..5673de3d2 100755
--- a/docutils/test/test_writers/test_latex2e.py
+++ b/docutils/test/test_writers/test_latex2e.py
@@ -409,9 +409,8 @@ first section
-------------
""",
# expected output
-head_template.substitute(dict(parts, requirements=parts['requirements'] +
-r"""\setcounter{secnumdepth}{0}
-""")) + r"""
+head_template.substitute(dict(parts, requirements=parts['requirements']
+ + '\\setcounter{secnumdepth}{0}\n')) + r"""
some text
diff --git a/docutils/test/test_writers/test_manpage.py b/docutils/test/test_writers/test_manpage.py
index 9df516ca4..16f160358 100644
--- a/docutils/test/test_writers/test_manpage.py
+++ b/docutils/test/test_writers/test_manpage.py
@@ -55,8 +55,7 @@ totest['blank'] = [
["",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "" "" "" ""
+""" + indend_macros + r""".TH "" "" "" ""
.SH NAME
\-
.\" Generated by docutils manpage writer.
@@ -71,8 +70,7 @@ r""".TH "" "" "" ""
""",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "HELLO, WORLD." "" "" ""
+""" + indend_macros + r""".TH "HELLO, WORLD." "" "" ""
.SH NAME
Hello, world. \-
.sp
@@ -147,8 +145,7 @@ and . in a line and at line start
""",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "SIMPLE" 1 "2009-08-05" "0.1" "text processing"
+""" + indend_macros + r""".TH "SIMPLE" 1 "2009-08-05" "0.1" "text processing"
.SH NAME
simple \- The way to go
.SH SYNOPSIS
@@ -228,8 +225,7 @@ totest['table'] = [
'''\
.\\" Man page generated from reStructuredText.
.
-''' + indend_macros +
-'''.TH "" "" "" ""
+''' + indend_macros + '''.TH "" "" "" ""
.SH NAME
\\- \n\
.INDENT 0.0
@@ -286,8 +282,7 @@ $
"""\
.\\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-""".TH "" "" "" ""
+""" + indend_macros + """.TH "" "" "" ""
.SH NAME
\\- \n\
optin group with dot as group item
@@ -343,12 +338,10 @@ Section
'''\
.\\" Man page generated from reStructuredText.
.
-''' + indend_macros +
-'''.TH "DEFINITION LIST TEST" "" "" ""
+''' + indend_macros + '''.TH "DEFINITION LIST TEST" "" "" ""
.SH NAME
Definition List Test \\- \n\
-''' +
-'''.SS Abstract
+''' + '''.SS Abstract
.sp
Docinfo is required.
.SH SECTION
@@ -373,8 +366,7 @@ totest['cmdlineoptions'] = [
""",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "" "" "" ""
+""" + indend_macros + r""".TH "" "" "" ""
.SH NAME
\-
.INDENT 0.0
@@ -403,8 +395,7 @@ totest['citation'] = [
""",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "" "" "" ""
+""" + indend_macros + r""".TH "" "" "" ""
.SH NAME
\-
.IP [docutils] 5
@@ -423,8 +414,7 @@ totest['rubric'] = [
""",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "" "" "" ""
+""" + indend_macros + r""".TH "" "" "" ""
.SH NAME
\-
some rubric
@@ -447,8 +437,7 @@ They are "escaped" anywhere.
""",
r""".\" Man page generated from reStructuredText.
.
-""" + indend_macros +
-r""".TH "" "" "" ""
+""" + indend_macros + r""".TH "" "" "" ""
.SH NAME
\-
.INDENT 0.0
diff --git a/docutils/tools/quicktest.py b/docutils/tools/quicktest.py
index 9446332ab..ba2fa8122 100755
--- a/docutils/tools/quicktest.py
+++ b/docutils/tools/quicktest.py
@@ -154,8 +154,8 @@ def posixGetArgs(argv):
elif o in ['-V', '--version']:
sys.stderr.write('quicktest.py (Docutils %s%s)\n' %
(docutils.__version__,
- docutils.__version_details__ and
- ' [%s]'%docutils.__version_details__ or ''))
+ docutils.__version_details__
+ and ' [%s]'%docutils.__version_details__ or ''))
sys.exit()
elif o in ['-r', '--rawxml']:
outputFormat = 'rawxml'
diff --git a/docutils/tox.ini b/docutils/tox.ini
index e40dc1d3a..5ac01704b 100644
--- a/docutils/tox.ini
+++ b/docutils/tox.ini
@@ -39,7 +39,8 @@ ignore =
# Use your own judgment; …"
W503, # line break before binary operator
- W504, # line break after binary operator
+ # this is the recommended style (changed on April 16th, 2016)
+
W605, # invalid escape sequence
F401, # 'foo' imported but unused
F841, # local variable 'foo' is assigned to but never used