CodeQL documentation

Unused argument in a formatting call

ID: py/str-format/surplus-argument
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - quality
   - maintainability
   - useless-code
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

A formatting expression, that is an expression of the form the_format.format(args) or format(the_format, args), can have any number of arguments, provided that there are enough to match the format. However, surplus arguments are redundant and clutter the code, making it harder to read.

It is also possible that surplus arguments indicate a mistake in the format string.

Recommendation

Check that the format string is correct and then remove any surplus arguments.

Example

In the following example there are three arguments for the call to the str.format() method, but the format string only requires two. The third argument should be deleted.

def surplus_argument():
    the_format = "{} {}" # Used to be "{} {} {}"
    return the_format.format(1, 2, 3)

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy