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 — Too few arguments in formatting call — CodeQL query help documentation

Too few arguments in formatting call¶

ID: py/str-format/missing-argument
Kind: problem
Security severity: 
Severity: error
Precision: high
Tags:
   - quality
   - reliability
   - correctness
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), must have sufficient arguments to match the format. Otherwise, an IndexError will be raised.

Recommendation¶

Either change the format to match the arguments, or ensure that there are sufficient arguments.

Example¶

In the following example, only 2 arguments may be provided for the call to the str.format method, which is insufficient for the format string used. To fix this a third parameter should be provided on line 4.

def unsafe_format():
    the_format = "{} {} {}"
    if unlikely_condition():
        return the_format.format(1, 2)
    else:
        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.