summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-06-16 22:57:57 +0300
committercpopa <devnull@localhost>2014-06-16 22:57:57 +0300
commitc5e05b7c2e3079250a5e3b274b34aec5bf4c2aa9 (patch)
tree42ba89afbccd69a2d52779b82d7bdace9a3ec526
parentc86f5196aa899651dbf6667e86c7d3112def7159 (diff)
downloadpylint-c5e05b7c2e3079250a5e3b274b34aec5bf4c2aa9.tar.gz
Don't warn with 'bad-format-character' when encountering the 'a' format on Python 3.
-rw-r--r--ChangeLog3
-rw-r--r--checkers/utils.py8
-rw-r--r--test/input/func_e12xx.py2
-rw-r--r--test/input/func_e13xx.py1
-rw-r--r--test/messages/func_e12xx.txt2
-rw-r--r--test/messages/func_e13xx.txt1
-rw-r--r--test/messages/func_e13xx_py30.txt11
7 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b675d0..6f780b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@ ChangeLog for Pylint
--
* Fix unused-import false positive with Python 3 metaclasses (#143).
+ * Don't warn with 'bad-format-character' when encountering
+ the 'a' format on Python 3.
+
2014-04-30 -- 1.2.1
* Restore the ability to specify the init-hook option via the
configuration file, which was accidentally broken in 1.2.0.
diff --git a/checkers/utils.py b/checkers/utils.py
index e7d85d4..6f40538 100644
--- a/checkers/utils.py
+++ b/checkers/utils.py
@@ -19,6 +19,7 @@
"""
import re
+import sys
import string
import astroid
@@ -28,6 +29,7 @@ from logilab.common.compat import builtins
BUILTINS_NAME = builtins.__name__
COMP_NODE_TYPES = astroid.ListComp, astroid.SetComp, astroid.DictComp, astroid.GenExpr
+PY3K = sys.version_info[0] == 3
class NoSuchArgumentError(Exception):
@@ -345,7 +347,11 @@ def parse_format_string(format_string):
if char in 'hlL':
i, char = next_char(i)
# Parse the conversion type (mandatory).
- if char not in 'diouxXeEfFgGcrs%':
+ if PY3K:
+ flags = 'diouxXeEfFgGcrs%a'
+ else:
+ flags = 'diouxXeEfFgGcrs%'
+ if char not in flags:
raise UnsupportedFormatCharacter(i)
if key:
keys.add(key)
diff --git a/test/input/func_e12xx.py b/test/input/func_e12xx.py
index 6482c92..83df7ab 100644
--- a/test/input/func_e12xx.py
+++ b/test/input/func_e12xx.py
@@ -14,7 +14,7 @@ def pprint():
logging.info('', '') # 1205
logging.info('%s%', '') # 1201
logging.info('%s%s', '') # 1206
- logging.info('%s%a', '', '') # 1200
+ logging.info('%s%y', '', '') # 1200
logging.info('%s%s', '', '', '') # 1205
# These should be okay:
diff --git a/test/input/func_e13xx.py b/test/input/func_e13xx.py
index a0d39ef..1eaf598 100644
--- a/test/input/func_e13xx.py
+++ b/test/input/func_e13xx.py
@@ -18,4 +18,5 @@ def pprint():
print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 1303
print "%2z" % PARG_1
print "strange format %2" % PARG_2
+ print "works in 3 %a" % 1
diff --git a/test/messages/func_e12xx.txt b/test/messages/func_e12xx.txt
index 690e6f4..d0a8b9c 100644
--- a/test/messages/func_e12xx.txt
+++ b/test/messages/func_e12xx.txt
@@ -2,5 +2,5 @@ E: 13:pprint: Too many arguments for logging format string
E: 14:pprint: Too many arguments for logging format string
E: 15:pprint: Logging format string ends in middle of conversion specifier
E: 16:pprint: Not enough arguments for logging format string
-E: 17:pprint: Unsupported logging format character 'a' (0x61) at index 3
+E: 17:pprint: Unsupported logging format character 'y' (0x79) at index 3
E: 18:pprint: Too many arguments for logging format string
diff --git a/test/messages/func_e13xx.txt b/test/messages/func_e13xx.txt
index c130949..f2d0d36 100644
--- a/test/messages/func_e13xx.txt
+++ b/test/messages/func_e13xx.txt
@@ -7,6 +7,7 @@ E: 17:pprint: Expected mapping for format string, not Tuple
E: 18:pprint: Expected mapping for format string, not List
E: 19:pprint: Unsupported format character 'z' (0x7a) at index 2
E: 20:pprint: Format string ends in middle of conversion specifier
+E: 21:pprint: Unsupported format character 'a' (0x61) at index 12
W: 15:pprint: Unused key 'PARG_3' in format string dictionary
W: 16:pprint: Format string dictionary key should be a string, not 2
diff --git a/test/messages/func_e13xx_py30.txt b/test/messages/func_e13xx_py30.txt
new file mode 100644
index 0000000..7ac9fb1
--- /dev/null
+++ b/test/messages/func_e13xx_py30.txt
@@ -0,0 +1,11 @@
+E: 11:pprint: Not enough arguments for format string
+E: 12:pprint: Too many arguments for format string
+E: 13:pprint: Mixing named and unnamed conversion specifiers in format string
+E: 14:pprint: Missing key 'PARG_2' in format string dictionary
+E: 16:pprint: Missing key 'PARG_2' in format string dictionary
+E: 17:pprint: Expected mapping for format string, not Tuple
+E: 18:pprint: Expected mapping for format string, not List
+E: 19:pprint: Unsupported format character 'z' (0x7a) at index 2
+E: 20:pprint: Format string ends in middle of conversion specifier
+W: 15:pprint: Unused key 'PARG_3' in format string dictionary
+W: 16:pprint: Format string dictionary key should be a string, not 2 \ No newline at end of file