diff options
author | cpopa <devnull@localhost> | 2013-09-25 22:44:25 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2013-09-25 22:44:25 +0300 |
commit | 09832b4a8bdebb30d7b3c29466b7fd6dd4212a6a (patch) | |
tree | d18ac672a29eb6fefb4e32b463dbeba90fcfb3b4 | |
parent | a4d15ce1c88d8e6b8e48ccb3bf08d5abbb52723a (diff) | |
download | pylint-09832b4a8bdebb30d7b3c29466b7fd6dd4212a6a.tar.gz |
Add new string format checks.
-rw-r--r-- | checkers/strings.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/checkers/strings.py b/checkers/strings.py index f98e70d..13112cb 100644 --- a/checkers/strings.py +++ b/checkers/strings.py @@ -29,6 +29,7 @@ from pylint.checkers import utils from pylint.checkers.utils import check_messages _PY3K = sys.version_info >= (3, 0) +_PY26 = sys.version_info < (2, 7) MSGS = { 'E1300': ("Unsupported format character %r (%#02x) at index %d", @@ -87,6 +88,20 @@ MSGS = { conversion specifiers is used with an argument that \ is not required by the format string."), + 'W1303': ("Format string contains both automatic field numbering " + "and manual field specifiers", + "format-combined-specifiers", + "Usen when a format string contains both automatic \ + field numbering (e.g. '{}') and manual field \ + specification (e.g. '{0}')"), + 'W1304': ("Can't use automatic field numbering for this version", + "no-automatic-field-numbering", + "Usen for Python versions lower than 2.7 when a " + "format string is used with automatic field numbering " + "(e.g. '{}'). Only manual field numbering (e.g. '{0}') " + "or named fields (e.g. '{a}') can work.", + {'maxversion': (2, 6)}), + } OTHER_NODES = (astroid.Const, astroid.List, astroid.Backquote, @@ -244,6 +259,17 @@ class StringMethodsChecker(BaseChecker): self.add_message('bad-format-string', node=node) return + manual_keys = set([key for key in required_keys + if key.isdigit()]) + if required_keys - manual_keys: + self.add_message('format-combined-specifiers', + node=node) + return + + if _PY26 and required_num_args: + self.add_message('no-automatic-field-numbering', + node=node) + if required_keys and required_num_args: # The format string uses both named and unnamed format # specifiers. |