GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Unused argument in a formatting call — CodeQL query help 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-code-quality.qls
   - 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¶

  • Python Library Reference: String Formatting.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.