summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-08-09 00:35:14 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-08-09 00:35:14 +0300
commitbd3ec0e8b82946e8d2a0e30225213edc3e657f16 (patch)
tree11f82ceb537ad0af5fedea2d77550e5aee0249e2
parentc35df18866e9edb9722ecb1d5641c0608f18a4f7 (diff)
downloadpylint-bd3ec0e8b82946e8d2a0e30225213edc3e657f16.tar.gz
Handle additional keyword arguments when checking for unnecessary-lambdas.
-rw-r--r--pylint/checkers/base.py7
-rw-r--r--pylint/checkers/utils.py4
-rw-r--r--pylint/test/functional/unnecessary_lambda.py1
3 files changed, 10 insertions, 2 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index c9b9f1f..f698016 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -784,6 +784,13 @@ functions, methods
# ordinary_args[i].name == call.args[i].name.
if len(ordinary_args) != len(call.args):
return
+ # Verify that the call uses keyword values that aren't
+ # defined by the lambda arguments.
+ for kwarg in call.keywords or []:
+ if (not node.args.parent_of(kwarg.value)
+ and not isinstance(kwarg.value, astroid.Const)):
+ return
+
for i in range(len(ordinary_args)):
if not isinstance(call.args[i], astroid.Name):
return
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index bc790c5..1aac4b0 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -416,10 +416,10 @@ def get_argument_from_call(callfunc_node, position=None, keyword=None):
"""
if position is None and keyword is None:
raise ValueError('Must specify at least one of: position or keyword.')
- if position is not None:
+ if position is not None:
try:
return callfunc_node.args[position]
- except IndexError as error:
+ except IndexError:
pass
if keyword and callfunc_node.keywords:
for arg in callfunc_node.keywords:
diff --git a/pylint/test/functional/unnecessary_lambda.py b/pylint/test/functional/unnecessary_lambda.py
index fa1e122..4617109 100644
--- a/pylint/test/functional/unnecessary_lambda.py
+++ b/pylint/test/functional/unnecessary_lambda.py
@@ -45,6 +45,7 @@ _ = lambda list_arg, *args: _ANYARGS(args, *list_arg)
_ = lambda: _ANYARGS(*[3])
_ = lambda: _ANYARGS(**{'three': 3})
_ = lambda: _ANYARGS(*[3], **{'three': 3})
+_ = lambda: _ANYARGS(func=42)
# Don't warn about this.
_ = lambda: code().analysis()