diff options
Diffstat (limited to 'checkers/strings.py')
-rw-r--r-- | checkers/strings.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/checkers/strings.py b/checkers/strings.py index 6f6f3bb..11b2baa 100644 --- a/checkers/strings.py +++ b/checkers/strings.py @@ -345,6 +345,10 @@ class StringMethodsChecker(BaseChecker): node=node) return + check_args = False + # Consider "{[0]} {[1]}" as num_args. + num_args += sum(1 for field in named_fields + if field == '') if named_fields: for field in named_fields: if field not in named and field: @@ -356,7 +360,19 @@ class StringMethodsChecker(BaseChecker): self.add_message('unused-format-string-argument', node=node, args=(field, )) + # num_args can be 0 if manual_pos is not. + num_args = num_args or manual_pos + if positional or num_args: + if named or any(True for field in named_fields if field == ''): + # Verify the required number of positional arguments + # only if the .format got at least one keyword argument. + # This means that the format strings accepts both + # positional and named fields and we should warn + # when one of the them is missing or is extra. + check_args = True else: + check_args = True + if check_args: # num_args can be 0 if manual_pos is not. num_args = num_args or manual_pos if positional > num_args: |