diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2013-09-25 22:44:25 +0300 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2013-09-25 22:44:25 +0300 |
| commit | 2fa2745eba672e824e98e15b3de5925111b45d90 (patch) | |
| tree | dec5d3990a903e8b4f74e2a96fdff9dc0cc86fb0 /checkers/strings.py | |
| parent | 1f77376a7ce59f287776fbe21e8442f4bb9eaf2a (diff) | |
| download | pylint-git-2fa2745eba672e824e98e15b3de5925111b45d90.tar.gz | |
Add new string format checks.
--HG--
branch : format
Diffstat (limited to 'checkers/strings.py')
| -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 f98e70db7..13112cbb9 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. |
