utils: Fix redefined-builtin pylint warning
************* Module files.client.common_lib.utils
W:1083,18: Redefining built-in 'input' (redefined-builtin)
W:1719, 4: Redefining built-in 'dict' (redefined-builtin)
In one case (hash function), the pylint warning is disabled
as usage of the builtin name 'hash' is intentional.
BUG=chromium:847272
TEST=None
Change-Id: Idf92ff6b72a10f917aa88f3fd9d6e5fc0ea8e466
Signed-off-by: Kirtika Ruchandani <kirtika@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1184371
Commit-Ready: Kirtika Ruchandani <kirtika@chromium.org>
Tested-by: Kirtika Ruchandani <kirtika@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 8b783a5..4f032df 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -595,21 +595,22 @@
@param input: Optional input string that will be used to update the hash.
"""
+ # pylint: disable=redefined-builtin
if hashtype not in ['md5', 'sha1']:
raise ValueError("Unsupported hash type: %s" % hashtype)
try:
- hash = hashlib.new(hashtype)
+ computed_hash = hashlib.new(hashtype)
except NameError:
if hashtype == 'md5':
- hash = md5.new()
+ computed_hash = md5.new()
elif hashtype == 'sha1':
- hash = sha.new()
+ computed_hash = sha.new()
if input:
- hash.update(input)
+ computed_hash.update(input)
- return hash
+ return computed_hash
def get_file(src, dest, permissions=None):
@@ -1088,18 +1089,18 @@
return out
-def strip_unicode(input):
- if type(input) == list:
- return [strip_unicode(i) for i in input]
- elif type(input) == dict:
+def strip_unicode(input_obj):
+ if type(input_obj) == list:
+ return [strip_unicode(i) for i in input_obj]
+ elif type(input_obj) == dict:
output = {}
- for key in input.keys():
- output[str(key)] = strip_unicode(input[key])
+ for key in input_obj.keys():
+ output[str(key)] = strip_unicode(input_obj[key])
return output
- elif type(input) == unicode:
- return str(input)
+ elif type(input_obj) == unicode:
+ return str(input_obj)
else:
- return input
+ return input_obj
def get_cpu_percentage(function, *args, **dargs):
@@ -1724,15 +1725,15 @@
dictionary
"""
arg_re = re.compile(r'(\w+)[:=](.*)$')
- dict = {}
+ args_dict = {}
for arg in args:
match = arg_re.match(arg)
if match:
- dict[match.group(1).lower()] = match.group(2)
+ args_dict[match.group(1).lower()] = match.group(2)
else:
logging.warning("args_to_dict: argument '%s' doesn't match "
"'%s' pattern. Ignored.", arg, arg_re.pattern)
- return dict
+ return args_dict
def get_unused_port():