CodeQL documentation

Formatting string mixes implicitly and explicitly numbered fields

ID: py/str-format/mixed-fields
Kind: problem
Security severity: 
Severity: error
Precision: high
Tags:
   - quality
   - reliability
   - correctness
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 form the_format.format(args) or format(the_format, args), can use explicitly numbered fields, like {1}, or implicitly numbered fields, such as {}, but it cannot use both. Doing so will raise a ValueError.

Recommendation

Use either explicitly numbered fields or implicitly numbered fields, but be consistent.

Example

In the following example the formatting uses both implicit, {}, and explicit, {1}, numbering for fields, which is illegal.

def illegal_format():
    "{} {1}".format("spam", "eggs")

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy