mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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: Ie97d686748c9c952e87718a65f401c5f6f80a5c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3400616 Reviewed-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
This commit is contained in:
committed by
LUCI CQ
parent
9a4db25b50
commit
22bf605bb6
@@ -38,8 +38,8 @@ class ConstantString(object):
|
||||
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 @@ def _gclient_eval(node_or_string, filename='<unknown>', vars_dict=None):
|
||||
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 EvaluateCondition(condition, variables, referenced_variables=None):
|
||||
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 @@ def EvaluateCondition(condition, variables, referenced_variables=None):
|
||||
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 @@ def EvaluateCondition(condition, variables, referenced_variables=None):
|
||||
'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 @@ def EvaluateCondition(condition, variables, referenced_variables=None):
|
||||
'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 @@ def EvaluateCondition(condition, variables, referenced_variables=None):
|
||||
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 SetVar(gclient_dict, var_name, value):
|
||||
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 @@ def GetRevision(gclient_dict, dep_name):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user