Fix pylint too-many-return-statements errors

This patch fixes the errors noted by pylint whereby too many
return statements are within a single method/function.

The following errors were resolved:
************* Module bandit.core.context
R:196, 4: Too many return statements (10/6) (too-many-return-statements)

Change-Id: I1caf37effb94c4d8123f99d3bb485e1fa0af8272
This commit is contained in:
Eric Brown 2016-11-29 22:45:35 -08:00
parent c65767fdaa
commit 584c45247d
2 changed files with 14 additions and 13 deletions

View File

@ -200,51 +200,53 @@ class Context(object):
:return: The value of the AST literal
'''
if isinstance(literal, _ast.Num):
return literal.n
literal_value = literal.n
elif isinstance(literal, _ast.Str):
return literal.s
literal_value = literal.s
elif isinstance(literal, _ast.List):
return_list = list()
for li in literal.elts:
return_list.append(self._get_literal_value(li))
return return_list
literal_value = return_list
elif isinstance(literal, _ast.Tuple):
return_tuple = tuple()
for ti in literal.elts:
return_tuple = return_tuple + (self._get_literal_value(ti),)
return return_tuple
literal_value = return_tuple
elif isinstance(literal, _ast.Set):
return_set = set()
for si in literal.elts:
return_set.add(self._get_literal_value(si))
return return_set
literal_value = return_set
elif isinstance(literal, _ast.Dict):
return dict(zip(literal.keys, literal.values))
literal_value = dict(zip(literal.keys, literal.values))
elif isinstance(literal, _ast.Ellipsis):
# what do we want to do with this?
pass
literal_value = None
elif isinstance(literal, _ast.Name):
return literal.id
literal_value = literal.id
# NOTE(sigmavirus24): NameConstants are only part of the AST in Python
# 3. NameConstants tend to refer to things like True and False. This
# prevents them from being re-assigned in Python 3.
elif six.PY3 and isinstance(literal, _ast.NameConstant):
return str(literal.value)
literal_value = str(literal.value)
# NOTE(sigmavirus24): Bytes are only part of the AST in Python 3
elif six.PY3 and isinstance(literal, _ast.Bytes):
return literal.s
literal_value = literal.s
else:
return None
literal_value = None
return literal_value
def get_call_arg_value(self, argument_name):
'''Gets the value of a named argument in a function call.

View File

@ -14,7 +14,6 @@
# E1101: no-member
# R0204: redefined-variable-type
# R0902: too-many-instance-attributes
# R0911: too-many-return-statements
# R0912: too-many-branches
# R0913: too-many-arguments
# R0914: too-many-locals
@ -29,7 +28,7 @@
# W0613: unused-argument
# W0621: redefined-outer-name
# W0703: broad-except
disable=C0111,C0301,C0325,F0401,W0511,W0142,W0622,C0103,E1101,R0204,R0902,R0911,R0912,R0913,R0914,R0915,W0110,W0141,W0201,W0401,W0603,W0212,W0612,W0613,W0621,W0703
disable=C0111,C0301,C0325,F0401,W0511,W0142,W0622,C0103,E1101,R0204,R0902,R0912,R0913,R0914,R0915,W0110,W0141,W0201,W0401,W0603,W0212,W0612,W0613,W0621,W0703
[Basic]
# Variable names can be 1 to 31 characters long, with lowercase and underscores