CodeQL documentation

Unsupported format character

ID: py/percent-format/unsupported-character 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 printf-style format string (i.e. a string that is used as the left hand side of the % operator, such as fmt % arguments) must consist of valid conversion specifiers, such as %s, %d, etc. Otherwise, a ValueError will be raised.

Recommendation

Ensure a valid conversion specifier is used.

Example

In the following example, format_as_tuple_incorrect, %t is not a valid conversion specifier.

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

References