Even more coding style cleanup
Fixing some more pylint warnings:
W1401: Anomalous backslash in string
W0623: Redefining name 'name' from outer scope
W0702: No exception type(s) specified
E0102: name: function already defined line n
Change-Id: I5afcdb4771ce210390a79981937806e30900a93c
diff --git a/color.py b/color.py
index 9200a29..33bc877 100644
--- a/color.py
+++ b/color.py
@@ -36,7 +36,8 @@
'blink' : 5,
'reverse': 7}
-RESET = "\033[m"
+RESET = "\033[m" # pylint: disable=W1401
+ # backslash is not anomalous
def is_color(s):
return s in COLORS
@@ -51,7 +52,7 @@
if attr >= 0 or fg >= 0 or bg >= 0:
need_sep = False
- code = "\033["
+ code = "\033[" #pylint: disable=W1401
if attr >= 0:
code += chr(ord('0') + attr)
diff --git a/command.py b/command.py
index 0c3b360..babb833 100644
--- a/command.py
+++ b/command.py
@@ -71,7 +71,7 @@
groups = mp.config.GetString('manifest.groups')
if not groups:
groups = 'all,-notdefault,platform-' + platform.system().lower()
- groups = [x for x in re.split('[,\s]+', groups) if x]
+ groups = [x for x in re.split(r'[,\s]+', groups) if x]
if not args:
for project in all_projects.values():
diff --git a/git_command.py b/git_command.py
index a40e6c0..39f795f 100644
--- a/git_command.py
+++ b/git_command.py
@@ -132,15 +132,15 @@
gitdir = None):
env = os.environ.copy()
- for e in [REPO_TRACE,
+ for key in [REPO_TRACE,
GIT_DIR,
'GIT_ALTERNATE_OBJECT_DIRECTORIES',
'GIT_OBJECT_DIRECTORY',
'GIT_WORK_TREE',
'GIT_GRAFT_FILE',
'GIT_INDEX_FILE']:
- if e in env:
- del env[e]
+ if key in env:
+ del env[key]
if disable_editor:
_setenv(env, 'GIT_EDITOR', ':')
diff --git a/git_config.py b/git_config.py
index ae28855..d6510aa 100644
--- a/git_config.py
+++ b/git_config.py
@@ -35,7 +35,7 @@
R_HEADS = 'refs/heads/'
R_TAGS = 'refs/tags/'
-ID_RE = re.compile('^[0-9a-f]{40}$')
+ID_RE = re.compile(r'^[0-9a-f]{40}$')
REVIEW_CACHE = dict()
@@ -288,7 +288,8 @@
d = self._do('--null', '--list')
if d is None:
return c
- for line in d.rstrip('\0').split('\0'):
+ for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401
+ # Backslash is not anomalous
if '\n' in line:
key, val = line.split('\n', 1)
else:
diff --git a/git_refs.py b/git_refs.py
index 18c9230..cfeffba 100644
--- a/git_refs.py
+++ b/git_refs.py
@@ -138,14 +138,14 @@
def _ReadLoose1(self, path, name):
try:
fd = open(path, 'rb')
- except:
+ except IOError:
return
try:
try:
mtime = os.path.getmtime(path)
ref_id = fd.readline()
- except:
+ except (IOError, OSError):
return
finally:
fd.close()
diff --git a/main.py b/main.py
index ba40d56..7a09c6b 100755
--- a/main.py
+++ b/main.py
@@ -27,7 +27,6 @@
import netrc
import optparse
import os
-import re
import sys
import time
import urllib2
diff --git a/manifest_xml.py b/manifest_xml.py
index dd163be..cdee87a 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -584,7 +584,7 @@
groups = ''
if node.hasAttribute('groups'):
groups = node.getAttribute('groups')
- groups = [x for x in re.split('[,\s]+', groups) if x]
+ groups = [x for x in re.split(r'[,\s]+', groups) if x]
default_groups = ['all', 'name:%s' % name, 'path:%s' % path]
groups.extend(set(default_groups).difference(groups))
diff --git a/project.py b/project.py
index 2f47169..6e8bb03 100644
--- a/project.py
+++ b/project.py
@@ -1012,6 +1012,10 @@
self.CleanPublishedCache(all_refs)
revid = self.GetRevisionId(all_refs)
+ def _doff():
+ self._FastForward(revid)
+ self._CopyFiles()
+
self._InitWorkTree()
head = self.work_git.GetHead()
if head.startswith(R_HEADS):
@@ -1090,9 +1094,6 @@
# All published commits are merged, and thus we are a
# strict subset. We can fast-forward safely.
#
- def _doff():
- self._FastForward(revid)
- self._CopyFiles()
syncbuf.later1(self, _doff)
return
@@ -1155,9 +1156,6 @@
syncbuf.fail(self, e)
return
else:
- def _doff():
- self._FastForward(revid)
- self._CopyFiles()
syncbuf.later1(self, _doff)
def AddCopyFile(self, src, dest, absdest):
@@ -1836,7 +1834,8 @@
if p.Wait() == 0:
out = p.stdout
if out:
- return out[:-1].split("\0")
+ return out[:-1].split('\0') # pylint: disable=W1401
+ # Backslash is not anomalous
return []
def DiffZ(self, name, *args):
@@ -1852,7 +1851,7 @@
out = p.process.stdout.read()
r = {}
if out:
- out = iter(out[:-1].split('\0'))
+ out = iter(out[:-1].split('\0')) # pylint: disable=W1401
while out:
try:
info = out.next()
diff --git a/subcmds/grep.py b/subcmds/grep.py
index 0dc8f9f..b067629 100644
--- a/subcmds/grep.py
+++ b/subcmds/grep.py
@@ -51,7 +51,7 @@
Look for a line that has '#define' and either 'MAX_PATH or 'PATH_MAX':
- repo grep -e '#define' --and -\( -e MAX_PATH -e PATH_MAX \)
+ repo grep -e '#define' --and -\\( -e MAX_PATH -e PATH_MAX \\)
Look for a line that has 'NODE' or 'Unexpected' in files that
contain a line that matches both expressions:
diff --git a/subcmds/init.py b/subcmds/init.py
index e56b922..48df9e8 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -147,7 +147,7 @@
r.ResetFetch()
r.Save()
- groups = re.split('[,\s]+', opt.groups)
+ groups = re.split(r'[,\s]+', opt.groups)
all_platforms = ['linux', 'darwin']
platformize = lambda x: 'platform-' + x
if opt.platform == 'auto':
diff --git a/subcmds/sync.py b/subcmds/sync.py
index d4637d0..8e9477a 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -696,7 +696,7 @@
try:
try:
self._times = pickle.load(f)
- except:
+ except IOError:
try:
os.remove(self._path)
except OSError:
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 84a5e44..39721ac 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -297,7 +297,7 @@
try:
# refs/changes/XYZ/N --> XYZ
return refs.get(last_pub).split('/')[-2]
- except:
+ except (AttributeError, IndexError):
return ""
def _UploadAndReport(self, opt, todo, original_people):