diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | checkers/strings.py | 2 | ||||
-rw-r--r-- | test/functional/string_formatting.py | 10 |
3 files changed, 17 insertions, 1 deletions
@@ -4,6 +4,12 @@ ChangeLog for Pylint -- * Don't require a docstring for empty modules. Closes issue #261. + * Fix a false positive with `too-few-format-args` string warning, + emitted when the string format contained a normal positional + argument ('{0}'), mixed with a positional argument which did + an attribute access ('{0.__class__}'). + Closes issue #463. + 2015-01-16 -- 1.4.1 diff --git a/checkers/strings.py b/checkers/strings.py index e88085d..8892c2c 100644 --- a/checkers/strings.py +++ b/checkers/strings.py @@ -181,7 +181,7 @@ def parse_format_method_string(format_string): if isinstance(keyname, numbers.Number): # In Python 2 it will return long which will lead # to different output between 2 and 3 - manual_pos_arg.add(keyname) + manual_pos_arg.add(str(keyname)) keyname = int(keyname) keys.append((keyname, list(fielditerator))) else: diff --git a/test/functional/string_formatting.py b/test/functional/string_formatting.py index 94554c6..dd7e4ea 100644 --- a/test/functional/string_formatting.py +++ b/test/functional/string_formatting.py @@ -171,3 +171,13 @@ def issue373(): return 'AAA{0[iface]}BBB{0[port]}'.format(self.opts)
return SomeClass
+
+def issue_463():
+ """
+ Mix positional arguments, `{0}`, with positional
+ arguments with attribute access, `{0.__x__}`.
+ """
+ data = "{0.__class__.__name__}: {0}".format(42)
+ data2 = "{0[0]}: {0}".format([1])
+ return (data, data2)
+
|