[Lint] Fix flake8 issues with l as var

This commit is contained in:
Calum Lind 2017-10-29 11:39:52 +00:00
parent 1730230244
commit 00dcd60d56
6 changed files with 34 additions and 33 deletions

View File

@ -81,7 +81,7 @@ decode_func[b'9'] = decode_string
def bdecode(x): def bdecode(x):
try: try:
r, l = decode_func[x[0:1]](x, 0) r, __ = decode_func[x[0:1]](x, 0)
except (IndexError, KeyError, ValueError): except (IndexError, KeyError, ValueError):
raise BTFailure('Not a valid bencoded string') raise BTFailure('Not a valid bencoded string')
else: else:

View File

@ -42,7 +42,7 @@ def raises_errors_as(error):
""" """
try: try:
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
except: except Exception:
(value, tb) = exc_info()[1:] (value, tb) = exc_info()[1:]
raise error, value, tb raise error, value, tb
return wrapper return wrapper

View File

@ -311,10 +311,10 @@ def loads(x, decode_utf8=False):
global _decode_utf8 global _decode_utf8
_decode_utf8 = decode_utf8 _decode_utf8 = decode_utf8
try: try:
r, l = decode_func[x[0:1]](x, 0) r, f = decode_func[x[0:1]](x, 0)
except (IndexError, KeyError): except (IndexError, KeyError):
raise ValueError raise ValueError
if l != len(x): if f != len(x):
raise ValueError raise ValueError
return r return r

View File

@ -777,20 +777,21 @@ class CmdLine(BaseMode, Commander):
possible_matches.append(escaped_name) possible_matches.append(escaped_name)
break break
else: else:
l = len(raw_line) line_len = len(raw_line)
# Let's avoid listing all torrents twice if there's no pattern # Let's avoid listing all torrents twice if there's no pattern
if not empty and torrent_id.startswith(line): if not empty and torrent_id.startswith(line):
# Highlight the matching part # Highlight the matching part
text = '{!info!}%s{!input!}%s - "%s"' % (torrent_id[:l], torrent_id[l:], torrent_name) text = '{!info!}%s{!input!}%s - "%s"' % (
torrent_id[:line_len], torrent_id[line_len:], torrent_name)
possible_matches.append(text) possible_matches.append(text)
if torrent_name.startswith(line): if torrent_name.startswith(line):
text = '{!info!}%s{!input!}%s ({!cyan!}%s{!input!})' % ( text = '{!info!}%s{!input!}%s ({!cyan!}%s{!input!})' % (
escaped_name[:l], escaped_name[l:], torrent_id) escaped_name[:line_len], escaped_name[line_len:], torrent_id)
possible_matches.append(text) possible_matches.append(text)
elif torrent_name.lower().startswith(line.lower()): elif torrent_name.lower().startswith(line.lower()):
text = '{!info!}%s{!input!}%s ({!cyan!}%s{!input!})' % ( text = '{!info!}%s{!input!}%s ({!cyan!}%s{!input!})' % (
escaped_name[:l], escaped_name[l:], torrent_id) escaped_name[:line_len], escaped_name[line_len:], torrent_id)
possible_matches2.append(text) possible_matches2.append(text)
return possible_matches + possible_matches2 return possible_matches + possible_matches2

View File

@ -306,12 +306,12 @@ class TorrentView(InputKeyHandler):
todraw = [] todraw = []
# Affected lines are given when changing selected torrent # Affected lines are given when changing selected torrent
if lines: if lines:
for l in lines: for line in lines:
if l < tidx: if line < tidx:
continue continue
if l >= (tidx + self.torrent_rows) or l >= self.numtorrents: if line >= (tidx + self.torrent_rows) or line >= self.numtorrents:
break break
todraw.append((l, l - self.curoff, draw_row(l))) todraw.append((line, line - self.curoff, draw_row(line)))
else: else:
for i in range(tidx, tidx + self.torrent_rows): for i in range(tidx, tidx + self.torrent_rows):
if i >= self.numtorrents: if i >= self.numtorrents:

View File

@ -131,56 +131,56 @@ def make(filename, outfile):
# Parse the catalog # Parse the catalog
msgid = msgstr = '' msgid = msgstr = ''
lno = 0 lno = 0
for l in lines: for line in lines:
lno += 1 lno += 1
# If we get a comment line after a msgstr, this is a new entry # If we get a comment line after a msgstr, this is a new entry
if l[0] == '#' and section == section_str: if line[0] == '#' and section == section_str:
add(msgid, msgstr, fuzzy) add(msgid, msgstr, fuzzy)
section = None section = None
fuzzy = 0 fuzzy = 0
# Record a fuzzy mark # Record a fuzzy mark
if l[:2] == '#,' and (l.find('fuzzy') >= 0): if line[:2] == '#,' and (line.find('fuzzy') >= 0):
fuzzy = 1 fuzzy = 1
# Skip comments # Skip comments
if l[0] == '#': if line[0] == '#':
continue continue
# Start of msgid_plural section, separate from singular form with \0 # Start of msgid_plural section, separate from singular form with \0
if l.startswith('msgid_plural'): if line.startswith('msgid_plural'):
msgid += '\x00' msgid += '\x00'
l = l[12:] line = line[12:]
# Now we are in a msgid section, output previous section # Now we are in a msgid section, output previous section
elif l.startswith('msgid'): elif line.startswith('msgid'):
if section == section_str: if section == section_str:
add(msgid, msgstr, fuzzy) add(msgid, msgstr, fuzzy)
section = section_id section = section_id
l = l[5:] line = line[5:]
msgid = msgstr = '' msgid = msgstr = ''
# Now we are in a msgstr section # Now we are in a msgstr section
elif l.startswith('msgstr'): elif line.startswith('msgstr'):
section = section_str section = section_str
l = l[6:] line = line[6:]
# Check for plural forms # Check for plural forms
if l.startswith('['): if line.startswith('['):
# Separate plural forms with \0 # Separate plural forms with \0
if not l.startswith('[0]'): if not line.startswith('[0]'):
msgstr += '\x00' msgstr += '\x00'
# Ignore the index - must come in sequence # Ignore the index - must come in sequence
l = l[l.index(']') + 1:] line = line[line.index(']') + 1:]
# Skip empty lines # Skip empty lines
l = l.strip() line = line.strip()
if not l: if not line:
continue continue
l = ast.literal_eval(l) line = ast.literal_eval(line)
# Python 2 ast.literal_eval returns bytes. # Python 2 ast.literal_eval returns bytes.
if isinstance(l, bytes): if isinstance(line, bytes):
l = l.decode('utf8') line = line.decode('utf8')
if section == section_id: if section == section_id:
msgid += l msgid += line
elif section == section_str: elif section == section_str:
msgstr += l msgstr += line
else: else:
print('Syntax error on %s:%d' % (infile, lno), 'before:', file=sys.stderr) print('Syntax error on %s:%d' % (infile, lno), 'before:', file=sys.stderr)
print(l, file=sys.stderr) print(line, file=sys.stderr)
sys.exit(1) sys.exit(1)
# Add last entry # Add last entry
if section == section_str: if section == section_str: