Use pylint 2.7 for depot_tools
This includes a few fixes for specific errors, and disables several new
warnings introduced in this version, in order to allow for an incremental migration.
Bug:1262286
Change-Id: I4b8f8fc521386419a3121bbb07edc8ac83170a94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3413679
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
diff --git a/gclient_eval.py b/gclient_eval.py
index c0098e4..11141d1 100644
--- a/gclient_eval.py
+++ b/gclient_eval.py
@@ -38,8 +38,8 @@
def __eq__(self, other):
if isinstance(other, ConstantString):
return self.value == other.value
- else:
- return self.value == other
+
+ return self.value == other
def __hash__(self):
return self.value.__hash__()
@@ -304,13 +304,14 @@
raise ValueError(
'%s takes exactly one argument (file %r, line %s)' % (
node.func.id, filename, getattr(node, 'lineno', '<unknown>')))
+
if node.func.id == 'Str':
if isinstance(node.args[0], ast.Str):
return ConstantString(node.args[0].s)
raise ValueError('Passed a non-string to Str() (file %r, line%s)' % (
filename, getattr(node, 'lineno', '<unknown>')))
- else:
- arg = _convert(node.args[0])
+
+ arg = _convert(node.args[0])
if not isinstance(arg, basestring):
raise ValueError(
'Var\'s argument must be a variable name (file %r, line %s)' % (
@@ -540,16 +541,20 @@
def _convert(node, allow_tuple=False):
if isinstance(node, ast.Str):
return node.s
- elif isinstance(node, ast.Tuple) and allow_tuple:
+
+ if isinstance(node, ast.Tuple) and allow_tuple:
return tuple(map(_convert, node.elts))
- elif isinstance(node, ast.Name):
+
+ if isinstance(node, ast.Name):
if node.id in referenced_variables:
raise ValueError(
'invalid cyclic reference to %r (inside %r)' % (
node.id, condition))
- elif node.id in _allowed_names:
+
+ if node.id in _allowed_names:
return _allowed_names[node.id]
- elif node.id in variables:
+
+ if node.id in variables:
value = variables[node.id]
# Allow using "native" types, without wrapping everything in strings.
@@ -562,16 +567,18 @@
variables[node.id],
variables,
referenced_variables.union([node.id]))
- else:
- # Implicitly convert unrecognized names to strings.
- # If we want to change this, we'll need to explicitly distinguish
- # between arguments for GN to be passed verbatim, and ones to
- # be evaluated.
- return node.id
- elif not sys.version_info[:2] < (3, 4) and isinstance(
+
+ # Implicitly convert unrecognized names to strings.
+ # If we want to change this, we'll need to explicitly distinguish
+ # between arguments for GN to be passed verbatim, and ones to
+ # be evaluated.
+ return node.id
+
+ if not sys.version_info[:2] < (3, 4) and isinstance(
node, ast.NameConstant): # Since Python 3.4
return node.value
- elif isinstance(node, ast.BoolOp) and isinstance(node.op, ast.Or):
+
+ if isinstance(node, ast.BoolOp) and isinstance(node.op, ast.Or):
bool_values = []
for value in node.values:
bool_values.append(_convert(value))
@@ -580,7 +587,8 @@
'invalid "or" operand %r (inside %r)' % (
bool_values[-1], condition))
return any(bool_values)
- elif isinstance(node, ast.BoolOp) and isinstance(node.op, ast.And):
+
+ if isinstance(node, ast.BoolOp) and isinstance(node.op, ast.And):
bool_values = []
for value in node.values:
bool_values.append(_convert(value))
@@ -589,13 +597,15 @@
'invalid "and" operand %r (inside %r)' % (
bool_values[-1], condition))
return all(bool_values)
- elif isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.Not):
+
+ if isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.Not):
value = _convert(node.operand)
if not isinstance(value, bool):
raise ValueError(
'invalid "not" operand %r (inside %r)' % (value, condition))
return not value
- elif isinstance(node, ast.Compare):
+
+ if isinstance(node, ast.Compare):
if len(node.ops) != 1:
raise ValueError(
'invalid compare: exactly 1 operator required (inside %r)' % (
@@ -619,10 +629,10 @@
raise ValueError(
'unexpected operator: %s %s (inside %r)' % (
node.ops[0], ast.dump(node), condition))
- else:
- raise ValueError(
- 'unexpected AST node: %s %s (inside %r)' % (
- node, ast.dump(node), condition))
+
+ raise ValueError(
+ 'unexpected AST node: %s %s (inside %r)' % (
+ node, ast.dump(node), condition))
return _convert(main_node)
@@ -738,7 +748,8 @@
def _GetVarName(node):
if isinstance(node, ast.Call):
return node.args[0].s
- elif node.s.endswith('}'):
+
+ if node.s.endswith('}'):
last_brace = node.s.rfind('{')
return node.s[last_brace+1:-1]
return None
@@ -880,12 +891,14 @@
dep = gclient_dict['deps'][dep_name]
if dep is None:
return None
- elif isinstance(dep, basestring):
+
+ if isinstance(dep, basestring):
_, _, revision = dep.partition('@')
return revision or None
- elif isinstance(dep, collections_abc.Mapping) and 'url' in dep:
+
+ if isinstance(dep, collections_abc.Mapping) and 'url' in dep:
_, _, revision = dep['url'].partition('@')
return revision or None
- else:
- raise ValueError(
- '%s is not a valid git dependency.' % dep_name)
+
+ raise ValueError(
+ '%s is not a valid git dependency.' % dep_name)