CodeQL documentation

Wrong number of arguments for format

ID: py/percent-format/wrong-arguments
Kind: problem
Security severity: 
Severity: error
Precision: very-high
   - reliability
   - correctness
   - external/cwe/cwe-685
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 format fmt % arguments must have the correct number of arguments on the right hand side of the expression. Otherwise, a TypeError will be raised.


Change the format to match the arguments and ensure that the right hand argument always has the correct number of elements.


In the following example the right hand side of the formatting operation can be of length 2, which does not match the format string.

def unsafe_format():
    if unlikely_condition():
        args = (1,2)
        args = (1, 2, 3)
    return "%s %s %s" % args


  • © GitHub, Inc.
  • Terms
  • Privacy