summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-07-29 14:56:19 +0300
committercpopa <devnull@localhost>2014-07-29 14:56:19 +0300
commitda03d60582b624729f578f0b6dfa0c2c08184c7f (patch)
tree16ec5d7f159179ec7f33a8ff49f2cc7c28607d51
parentbe5921dd65f379f2dbdbd0f32d546bde9d517403 (diff)
downloadpylint-da03d60582b624729f578f0b6dfa0c2c08184c7f.tar.gz
Fix a false positive with string formatting checker, when using keyword argument packing. Closes issue #288.
-rw-r--r--ChangeLog3
-rw-r--r--checkers/strings.py16
-rw-r--r--test/input/func_string_format_py27.py8
3 files changed, 22 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 4bef070..b5bea9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@ ChangeLog for Pylint
encountering a string which uses only position-based arguments.
Closes issue #285.
+ * Fix a false positive with string formatting checker, when using
+ keyword argument packing. Closes issue #288.
+
2014-07-26 -- 1.3.0
* Allow hanging continued indentation for implicitly concatenated
diff --git a/checkers/strings.py b/checkers/strings.py
index a07482a..6f6f3bb 100644
--- a/checkers/strings.py
+++ b/checkers/strings.py
@@ -386,24 +386,30 @@ class StringMethodsChecker(BaseChecker):
key = 0
if isinstance(key, int):
try:
- argument = utils.get_argument_from_call(node, key)
+ argname = utils.get_argument_from_call(node, key)
except utils.NoSuchArgumentError:
continue
else:
if key not in named:
continue
- argument = named[key]
- if argument in (astroid.YES, None):
+ argname = named[key]
+ if argname in (astroid.YES, None):
continue
try:
- argument = argument.infer().next()
+ argument = argname.infer().next()
except astroid.InferenceError:
continue
if not specifiers or argument is astroid.YES:
# No need to check this key if it doesn't
# use attribute / item access
continue
-
+ if argument.parent and isinstance(argument.parent, astroid.Arguments):
+ # Check to see if our argument is kwarg or vararg,
+ # and skip the check for this argument if so, because when inferring,
+ # astroid will return empty objects (dicts and tuples) and
+ # that can lead to false positives.
+ if argname.name in (argument.parent.kwarg, argument.parent.vararg):
+ continue
previous = argument
parsed = []
for is_attribute, specifier in specifiers:
diff --git a/test/input/func_string_format_py27.py b/test/input/func_string_format_py27.py
index 38eafd1..e2bfe12 100644
--- a/test/input/func_string_format_py27.py
+++ b/test/input/func_string_format_py27.py
@@ -78,3 +78,11 @@ def pprint_bad():
print "{0.missing}".format(2)
print "{0} {1} {2}".format(1, 2)
print "{0} {1}".format(1, 2, 3)
+
+def good_issue288(*args, **kwargs):
+ """ Test that using kwargs does not emit a false
+ positive.
+ """
+ data = 'Hello John Doe {0[0]}'.format(args)
+ print data
+ return 'Hello {0[name]}'.format(kwargs)