diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-07-08 14:32:09 +0200 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-07-08 14:32:09 +0200 |
commit | 67bbca5f8bb04314a981f27d25048d26b490e91c (patch) | |
tree | a0f97ddbe1453a07a0199a5e4529b56f9d94a12b | |
parent | 8c9dd0eddc6d75f1bca1688b23ef11cc43eb56fc (diff) | |
download | pylint-git-67bbca5f8bb04314a981f27d25048d26b490e91c.tar.gz |
built-in checkers use [01-50] base message ids (closes #68057)
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | checkers/__init__.py | 5 | ||||
-rw-r--r-- | checkers/logging.py | 22 | ||||
-rw-r--r-- | checkers/string_format.py | 36 | ||||
-rw-r--r-- | doc/features.txt | 36 | ||||
-rw-r--r-- | test/input/func_e12xx.py (renamed from test/input/func_e65xx.py) | 12 | ||||
-rw-r--r-- | test/input/func_e13xx.py | 21 | ||||
-rw-r--r-- | test/input/func_e99xx.py | 21 | ||||
-rw-r--r-- | test/input/func_w1201.py (renamed from test/input/func_w6501.py) | 0 | ||||
-rw-r--r-- | test/messages/func_e12xx.txt (renamed from test/messages/func_e65xx.txt) | 0 | ||||
-rw-r--r-- | test/messages/func_e13xx.txt (renamed from test/messages/func_e99xx.txt) | 0 | ||||
-rw-r--r-- | test/messages/func_w1201.txt (renamed from test/messages/func_w6501.txt) | 0 |
12 files changed, 93 insertions, 68 deletions
@@ -2,11 +2,15 @@ ChangeLog for PyLint ==================== -- - + * ids of logging and string_format checkers have been changed: + logging: 65 -> 12, string_format: 99 -> 13 + Also add documentation to say that ids of range 1-50 shall be reserved + to pylint internal checkers + * #69993: Additional string format checks for logging module: check for missing arguments, too many arguments, or invalid string formats in the logging checker module. Contributed by Daniel Arena - + * #69220: add column offset to the reports. If you've a custom reporter, this change may break it has now location gain a new item giving the column offset. diff --git a/checkers/__init__.py b/checkers/__init__.py index e9d7e2154..d33cacf34 100644 --- a/checkers/__init__.py +++ b/checkers/__init__.py @@ -27,9 +27,14 @@ Base id of standard checkers (used in msg and report ids): 09: design_analysis 10: newstyle 11: typecheck +12: logging +13: string_format +14-50: not yet used: reserved for future internal checkers. +51-99: perhaps used: reserved for external checkers The raw_metrics checker has no number associated since it doesn't emit any messages nor reports. XXX not true, emit a 07 report ! + """ import tokenize diff --git a/checkers/logging.py b/checkers/logging.py index f19273b93..89899b656 100644 --- a/checkers/logging.py +++ b/checkers/logging.py @@ -21,7 +21,7 @@ from pylint.checkers import utils MSGS = { - 'W6501': ('Specify string format arguments as logging function parameters', + 'W1201': ('Specify string format arguments as logging function parameters', 'Used when a logging statement has a call form of ' '"logging.<logging method>(format_string % (format_args...))". ' 'Such calls should leave string interpolation to the logging ' @@ -31,15 +31,15 @@ MSGS = { 'interpolation in those cases in which no message will be ' 'logged. For more, see ' 'http://www.python.org/dev/peps/pep-0282/.'), - 'E6500': ('Unsupported logging format character %r (%#02x) at index %d', + 'E1200': ('Unsupported logging format character %r (%#02x) at index %d', 'Used when an unsupported format character is used in a logging\ statement format string.'), - 'E6501': ('Logging format string ends in middle of conversion specifier', + 'E1201': ('Logging format string ends in middle of conversion specifier', 'Used when a logging statement format string terminates before\ the end of a conversion specifier.'), - 'E6505': ('Too many arguments for logging format string', + 'E1205': ('Too many arguments for logging format string', 'Used when a logging format string is given too few arguments.'), - 'E6506': ('Not enough arguments for logging format string', + 'E1206': ('Not enough arguments for logging format string', 'Used when a logging format string is given too many arguments'), } @@ -90,7 +90,7 @@ class LoggingChecker(checkers.BaseChecker): # scope of this checker. return if isinstance(node.args[0], astng.BinOp) and node.args[0].op == '%': - self.add_message('W6501', node=node) + self.add_message('W1201', node=node) elif isinstance(node.args[0], astng.Const): self._check_format_string(node, 0) @@ -103,7 +103,7 @@ class LoggingChecker(checkers.BaseChecker): # the scope of this checker. return if isinstance(node.args[1], astng.BinOp) and node.args[1].op == '%': - self.add_message('W6501', node=node) + self.add_message('W1201', node=node) elif isinstance(node.args[1], astng.Const): self._check_format_string(node, 1) @@ -134,15 +134,15 @@ class LoggingChecker(checkers.BaseChecker): return except utils.UnsupportedFormatCharacter, e: c = format_string[e.index] - self.add_message('E6500', node=node, args=(c, ord(c), e.index)) + self.add_message('E1200', node=node, args=(c, ord(c), e.index)) return except utils.IncompleteFormatString: - self.add_message('E6501', node=node) + self.add_message('E1201', node=node) return if num_args > required_num_args: - self.add_message('E6505', node=node) + self.add_message('E1205', node=node) elif num_args < required_num_args: - self.add_message('E6506', node=node) + self.add_message('E1206', node=node) def _count_supplied_tokens(self, args): """Counts the number of tokens in an args list. diff --git a/checkers/string_format.py b/checkers/string_format.py index d57c05973..c420a604b 100644 --- a/checkers/string_format.py +++ b/checkers/string_format.py @@ -26,35 +26,35 @@ from pylint.checkers import utils MSGS = { - 'E9900': ("Unsupported format character %r (%#02x) at index %d", + 'E1300': ("Unsupported format character %r (%#02x) at index %d", "Used when a unsupported format character is used in a format\ string."), - 'E9901': ("Format string ends in middle of conversion specifier", + 'E1301': ("Format string ends in middle of conversion specifier", "Used when a format string terminates before the end of a \ conversion specifier."), - 'E9902': ("Mixing named and unnamed conversion specifiers in format string", + 'E1302': ("Mixing named and unnamed conversion specifiers in format string", "Used when a format string contains both named (e.g. '%(foo)d') \ and unnamed (e.g. '%d') conversion specifiers. This is also \ used when a named conversion specifier contains * for the \ minimum field width and/or precision."), - 'E9903': ("Expected mapping for format string, not %s", + 'E1303': ("Expected mapping for format string, not %s", "Used when a format string that uses named conversion specifiers \ is used with an argument that is not a mapping."), - 'W9900': ("Format string dictionary key should be a string, not %s", + 'W1300': ("Format string dictionary key should be a string, not %s", "Used when a format string that uses named conversion specifiers \ is used with a dictionary whose keys are not all strings."), - 'W9901': ("Unused key %r in format string dictionary", + 'W1301': ("Unused key %r in format string dictionary", "Used when a format string that uses named conversion specifiers \ is used with a dictionary that conWtains keys not required by the \ format string."), - 'E9904': ("Missing key %r in format string dictionary", + 'E1304': ("Missing key %r in format string dictionary", "Used when a format string that uses named conversion specifiers \ is used with a dictionary that doesn't contain all the keys \ required by the format string."), - 'E9905': ("Too many arguments for format string", + 'E1305': ("Too many arguments for format string", "Used when a format string that uses unnamed conversion \ specifiers is given too few arguments."), - 'E9906': ("Not enough arguments for format string", + 'E1306': ("Not enough arguments for format string", "Used when a format string that uses unnamed conversion \ specifiers is given too many arguments"), } @@ -87,15 +87,15 @@ class StringFormatChecker(BaseChecker): utils.parse_format_string(format_string) except utils.UnsupportedFormatCharacter, e: c = format_string[e.index] - self.add_message('E9900', node=node, args=(c, ord(c), e.index)) + self.add_message('E1300', node=node, args=(c, ord(c), e.index)) return except utils.IncompleteFormatString: - self.add_message('E9901', node=node) + self.add_message('E1301', node=node) return if required_keys and required_num_args: # The format string uses both named and unnamed format # specifiers. - self.add_message('E9902', node=node) + self.add_message('E1302', node=node) elif required_keys: # The format string uses only named format specifiers. # Check that the RHS of the % operator is a mapping object @@ -110,7 +110,7 @@ class StringFormatChecker(BaseChecker): if isinstance(key, basestring): keys.add(key) else: - self.add_message('W9900', node=node, args=key) + self.add_message('W1300', node=node, args=key) else: # One of the keys was something other than a # constant. Since we can't tell what it is, @@ -120,13 +120,13 @@ class StringFormatChecker(BaseChecker): if not unknown_keys: for key in required_keys: if key not in keys: - self.add_message('E9904', node=node, args=key) + self.add_message('E1304', node=node, args=key) for key in keys: if key not in required_keys: - self.add_message('W9901', node=node, args=key) + self.add_message('W1301', node=node, args=key) elif isinstance(args, OTHER_NODES + (astng.Tuple,)): type_name = type(args).__name__ - self.add_message('E9903', node=node, args=type_name) + self.add_message('E1303', node=node, args=type_name) # else: # The RHS of the format specifier is a name or # expression. It may be a mapping object, so @@ -147,9 +147,9 @@ class StringFormatChecker(BaseChecker): num_args = None if num_args is not None: if num_args > required_num_args: - self.add_message('E9905', node=node) + self.add_message('E1305', node=node) elif num_args < required_num_args: - self.add_message('E9906', node=node) + self.add_message('E1306', node=node) def register(linter): diff --git a/doc/features.txt b/doc/features.txt index e8f41c75b..d32123815 100644 --- a/doc/features.txt +++ b/doc/features.txt @@ -105,7 +105,7 @@ logging checker Messages ~~~~~~~~ -:W6501: *Specify string format arguments as logging function parameters* +:W1201: *Specify string format arguments as logging function parameters* Used when a logging statement has a call form of "logging.<logging method>(format_string % (format_args...))". Such calls should leave string interpolation to the logging method itself and be written "logging.<logging @@ -113,6 +113,19 @@ Messages incurring the cost of the interpolation in those cases in which no message will be logged. For more, see http://www.python.org/dev/peps/pep-0282/. +:E1200: *Unsupported logging format character %r (%#02x) at index %d* + Used when an unsupported format character is used in a logging statement + format string. + +:E1201: *'Logging format string ends in middle of conversion specifier* + Used when a logging statement format string terminates before the end of a + conversion specifier. + +:E1205: *Too many arguments for logging format string* + Used when a logging format string is given too few arguments. + +:E1206: *Not enough arguments for logging format string* + Used when a logging format string is given too many arguments. similarities checker -------------------- @@ -149,30 +162,30 @@ string_format checker Messages ~~~~~~~~ -:E9900: *Unsupported format character %r (%#02x) at index %d* +:E1300: *Unsupported format character %r (%#02x) at index %d* Used when a unsupported format character is used in a format string. -:E9901: *Format string ends in middle of conversion specifier* +:E1301: *Format string ends in middle of conversion specifier* Used when a format string terminates before the end of a conversion specifier. -:E9902: *Mixing named and unnamed conversion specifiers in format string* +:E1302: *Mixing named and unnamed conversion specifiers in format string* Used when a format string contains both named (e.g. '%(foo)d') and unnamed (e.g. '%d') conversion specifiers. This is also used when a named conversion specifier contains * for the minimum field width and/or precision. -:E9903: *Expected mapping for format string, not %s* +:E1303: *Expected mapping for format string, not %s* Used when a format string that uses named conversion specifiers is used with an argument that is not a mapping. -:E9904: *Missing key %r in format string dictionary* +:E1304: *Missing key %r in format string dictionary* Used when a format string that uses named conversion specifiers is used with a dictionary that doesn't contain all the keys required by the format string. -:E9905: *Too many arguments for format string* +:E1305: *Too many arguments for format string* Used when a format string that uses unnamed conversion specifiers is given too few arguments. -:E9906: *Not enough arguments for format string* +:E1306: *Not enough arguments for format string* Used when a format string that uses unnamed conversion specifiers is given too many arguments -:W9900: *Format string dictionary key should be a string, not %s* +:W1300: *Format string dictionary key should be a string, not %s* Used when a format string that uses named conversion specifiers is used with a dictionary whose keys are not all strings. -:W9901: *Unused key %r in format string dictionary* +:W1301: *Unused key %r in format string dictionary* Used when a format string that uses named conversion specifiers is used with a dictionary that conWtains keys not required by the format string. @@ -657,6 +670,9 @@ Messages This is a particular case of W0104 with its own message so you can easily disable it if you're using those strings as documentation, instead of comments. +:W0106: *Expression "%s" is assigned to nothing',* + Used when an expression that is not a function call is assigned to nothing. + Probably something else was intended. :W0107: *Unnecessary pass statement* Used when a "pass" statement that can be avoided is encountered.) :W0108: *Lambda may not be necessary* diff --git a/test/input/func_e65xx.py b/test/input/func_e12xx.py index 854c34796..6482c9266 100644 --- a/test/input/func_e65xx.py +++ b/test/input/func_e12xx.py @@ -10,12 +10,12 @@ def pprint(): """Test string format in logging statements. """ # These should all emit lint errors: - logging.info(0, '') # 6505 - logging.info('', '') # 6505 - logging.info('%s%', '') # 6501 - logging.info('%s%s', '') # 6506 - logging.info('%s%a', '', '') # 6500 - logging.info('%s%s', '', '', '') # 6505 + logging.info(0, '') # 1205 + logging.info('', '') # 1205 + logging.info('%s%', '') # 1201 + logging.info('%s%s', '') # 1206 + logging.info('%s%a', '', '') # 1200 + logging.info('%s%s', '', '', '') # 1205 # These should be okay: logging.info(1) diff --git a/test/input/func_e13xx.py b/test/input/func_e13xx.py new file mode 100644 index 000000000..a0d39efa3 --- /dev/null +++ b/test/input/func_e13xx.py @@ -0,0 +1,21 @@ +"""test string format error +""" + +__revision__ = 1 + +PARG_1 = PARG_2 = PARG_3 = 1 + +def pprint(): + """Test string format + """ + print "%s %s" % {'PARG_1': 1, 'PARG_2': 2} # E1306 + print "%s" % (PARG_1, PARG_2) # E1305 + print "%(PARG_1)d %d" % {'PARG_1': 1, 'PARG_2': 2} # E1302 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1} # E1304 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 'PARG_2':2, 'PARG_3':3}#W1301 + print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 2:3} # W1300 E1304 + print "%(PARG_1)d %(PARG_2)d" % (2, 3) # 1303 + print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 1303 + print "%2z" % PARG_1 + print "strange format %2" % PARG_2 + diff --git a/test/input/func_e99xx.py b/test/input/func_e99xx.py deleted file mode 100644 index 34af89c44..000000000 --- a/test/input/func_e99xx.py +++ /dev/null @@ -1,21 +0,0 @@ -"""test string format error -""" - -__revision__ = 1 - -PARG_1 = PARG_2 = PARG_3 = 1 - -def pprint(): - """Test string format - """ - print "%s %s" % {'PARG_1': 1, 'PARG_2': 2} # E9906 - print "%s" % (PARG_1, PARG_2) # E9905 - print "%(PARG_1)d %d" % {'PARG_1': 1, 'PARG_2': 2} # E9902 - print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1} # E9904 - print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 'PARG_2':2, 'PARG_3':3}#W9901 - print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 2:3} # W9900 E9904 - print "%(PARG_1)d %(PARG_2)d" % (2, 3) # 9903 - print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 9903 - print "%2z" % PARG_1 - print "strange format %2" % PARG_2 - diff --git a/test/input/func_w6501.py b/test/input/func_w1201.py index 9013c2db3..9013c2db3 100644 --- a/test/input/func_w6501.py +++ b/test/input/func_w1201.py diff --git a/test/messages/func_e65xx.txt b/test/messages/func_e12xx.txt index 690e6f405..690e6f405 100644 --- a/test/messages/func_e65xx.txt +++ b/test/messages/func_e12xx.txt diff --git a/test/messages/func_e99xx.txt b/test/messages/func_e13xx.txt index c130949cb..c130949cb 100644 --- a/test/messages/func_e99xx.txt +++ b/test/messages/func_e13xx.txt diff --git a/test/messages/func_w6501.txt b/test/messages/func_w1201.txt index 45a742ece..45a742ece 100644 --- a/test/messages/func_w6501.txt +++ b/test/messages/func_w1201.txt |