CodeQL documentation

Unsupported format character

ID: py/percent-format/unsupported-character
Kind: problem
Security severity: 
Severity: error
Precision: high
Tags:
   - reliability
   - correctness
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

A format string, that is the string on the left hand side of an expression like fmt % arguments, must consist of legal conversion specifiers. Otherwise, a ValueError will be raised.

Recommendation

Choose a legal conversion specifier.

Example

In format_as_tuple_incorrect, “t” is not a legal conversion specifier.


def format_as_tuple_incorrect(args):
    return "%t" % args

def format_as_tuple_correct(args):
    return "%r" % (args,)

References

  • © GitHub, Inc.
  • Terms
  • Privacy