py: flake8 fixes

This commit is contained in:
Daniel Hahler 2019-07-29 04:43:49 +02:00
parent 97ce776e7b
commit d7b04ae7a7
6 changed files with 23 additions and 17 deletions

View File

@ -26,13 +26,13 @@ def get_color_code(bg, color_num):
prefix += 1 prefix += 1
color_num %= 8 color_num %= 8
else: else:
prefix = '48;5;' if bg else '38;5;' prefix = '48;5;' if bg else '38;5;'
return '\x1b[{0}{1}m'.format(prefix, color_num) return '\x1b[{0}{1}m'.format(prefix, color_num)
def highlight(attrs): def highlight(attrs):
fg, bg = [int(attrs['foreground']), int(attrs['background'])] fg, bg = [int(attrs['foreground']), int(attrs['background'])]
rv = [SGR0] # start with sgr0 rv = [SGR0] # start with sgr0
if fg != -1: if fg != -1:
rv.append(get_color_code(False, fg)) rv.append(get_color_code(False, fg))
if bg != -1: if bg != -1:

View File

@ -22,8 +22,6 @@ def main(argv):
args = argparser.parse_args(argv) args = argparser.parse_args(argv)
with args.file: with args.file:
include_dirs = []
iwyu = Popen(['include-what-you-use', '-xc'] + args.iwyu_args + ['/dev/stdin'], iwyu = Popen(['include-what-you-use', '-xc'] + args.iwyu_args + ['/dev/stdin'],
stdin=PIPE, stdout=PIPE, stderr=PIPE) stdin=PIPE, stdout=PIPE, stderr=PIPE)

View File

@ -86,7 +86,7 @@ SITENAVI_SEARCH = '<table width="100%"><tbody><tr><td>' + SITENAVI_LINKS_WEB + \
TEXTSTART = """ TEXTSTART = """
<div id="d1"> <div id="d1">
<pre id="sp"> </pre> <pre id="sp">""" + (" " * 80) + """</pre>
<div id="d2"> <div id="d2">
<pre> <pre>
""" """

View File

@ -36,7 +36,6 @@ import shutil
import textwrap import textwrap
import subprocess import subprocess
import collections import collections
import pprint
from xml.dom import minidom from xml.dom import minidom
@ -295,10 +294,9 @@ def render_params(parent, width=62):
out += '{}{}\n'.format(name, desc) out += '{}{}\n'.format(name, desc)
return out.rstrip() return out.rstrip()
# Renders a node as Vim help text, recursively traversing all descendants.
def render_node(n, text, prefix='', indent='', width=62): def render_node(n, text, prefix='', indent='', width=62):
"""Renders a node as Vim help text, recursively traversing all descendants."""
text = '' text = ''
# space_preceding = (len(text) > 0 and ' ' == text[-1][-1]) # space_preceding = (len(text) > 0 and ' ' == text[-1][-1])
# text += (int(not space_preceding) * ' ') # text += (int(not space_preceding) * ' ')
@ -322,9 +320,11 @@ def render_node(n, text, prefix='', indent='', width=62):
text += ' [verbatim] {}'.format(get_text(n)) text += ' [verbatim] {}'.format(get_text(n))
elif n.nodeName == 'listitem': elif n.nodeName == 'listitem':
for c in n.childNodes: for c in n.childNodes:
text += indent + prefix + \ text += (
render_node(c, text, indent=indent + indent
(' ' * len(prefix)), width=width) + prefix
+ render_node(c, text, indent=indent + (' ' * len(prefix)), width=width)
)
elif n.nodeName in ('para', 'heading'): elif n.nodeName in ('para', 'heading'):
for c in n.childNodes: for c in n.childNodes:
text += render_node(c, text, indent=indent, width=width) text += render_node(c, text, indent=indent, width=width)
@ -693,7 +693,8 @@ def gen_docs(config):
for filename in CONFIG[mode]['section_order']: for filename in CONFIG[mode]['section_order']:
if filename not in sections: if filename not in sections:
raise RuntimeError( raise RuntimeError(
'found new module "{}"; update the "section_order" map'.format(filename)) 'found new module "{}"; update the "section_order" map'.format(
filename))
title, helptag, section_doc = sections.pop(filename) title, helptag, section_doc = sections.pop(filename)
i += 1 i += 1
if filename not in CONFIG[mode]['append_only']: if filename not in CONFIG[mode]['append_only']:

View File

@ -2610,9 +2610,13 @@ def CheckBraces(filename, clean_lines, linenum, error):
'Brace starting function body must be placed on its own line') 'Brace starting function body must be placed on its own line')
else: else:
func_start_linenum = end_linenum + 1 func_start_linenum = end_linenum + 1
while not clean_lines.lines[func_start_linenum] == '{': while not clean_lines.lines[func_start_linenum] == "{":
attrline = Match(r'^((?!# *define).*?)(?:FUNC_ATTR|FUNC_API|REAL_FATTR)_\w+(?:\(\d+(, \d+)*\))?', attrline = Match(
clean_lines.lines[func_start_linenum]) r'^((?!# *define).*?)'
r'(?:FUNC_ATTR|FUNC_API|REAL_FATTR)_\w+'
r'(?:\(\d+(, \d+)*\))?',
clean_lines.lines[func_start_linenum],
)
if attrline: if attrline:
if len(attrline.group(1)) != 2: if len(attrline.group(1)) != 2:
error(filename, func_start_linenum, error(filename, func_start_linenum,
@ -3182,7 +3186,8 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
r'|li_(?:next|prev|tv))\b', line) r'|li_(?:next|prev|tv))\b', line)
if match: if match:
error(filename, linenum, 'runtime/deprecated', 4, error(filename, linenum, 'runtime/deprecated', 4,
'Accessing list_T internals directly is prohibited (hint: see commit d46e37cb4c71)') 'Accessing list_T internals directly is prohibited '
'(hint: see commit d46e37cb4c71)')
# Check for suspicious usage of "if" like # Check for suspicious usage of "if" like
# } if (a == b) { # } if (a == b) {

View File

@ -8,6 +8,7 @@ import locale
import io import io
import sys import sys
def set_output_encoding(enc=None): def set_output_encoding(enc=None):
"""Set the encoding of stdout and stderr """Set the encoding of stdout and stderr
@ -20,7 +21,7 @@ def set_output_encoding(enc=None):
def get_text_writer(fo, **kwargs): def get_text_writer(fo, **kwargs):
kw = dict(kwargs) kw = dict(kwargs)
kw.setdefault('errors', 'backslashreplace') # use \uXXXX style kw.setdefault('errors', 'backslashreplace') # use \uXXXX style
kw.setdefault('closefd', False) kw.setdefault('closefd', False)
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
@ -29,6 +30,7 @@ def set_output_encoding(enc=None):
writer = io.open(fo.fileno(), mode='w', newline='', **kw) writer = io.open(fo.fileno(), mode='w', newline='', **kw)
write = writer.write # save the original write() function write = writer.write # save the original write() function
enc = locale.getpreferredencoding() enc = locale.getpreferredencoding()
def convwrite(s): def convwrite(s):
if isinstance(s, bytes): if isinstance(s, bytes):
write(s.decode(enc)) # convert to unistr write(s.decode(enc)) # convert to unistr