flake8 plugin which forbids printf-style string formatting
Project description
flake8-printf-formatting
flake8 plugin which forbids printf-style string formatting
Installation
pip install flake8-printf-formatting
Codes
Code | Description |
---|---|
MOD001 | do not use printf-style string formatting |
Rationale
The official Python 3 documentation doesn't recommend printf-style string formatting:
The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer formatted string literals, the
str.format
interface, or template strings may help avoid these errors. Each of these alternatives provides their own trade-offs and benefits of simplicity, flexibility, and/or extensibility.
Bad
print("Hello, %s!" % name)
Good
print("Hello, {name}!".format(name=name))
Even better
print(f"Hello, {name}!")
As a pre-commit hook
See pre-commit for instructions
Sample .pre-commit-config.yaml
:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
hooks:
- id: flake8
additional_dependencies: [flake8-printf-formatting]
Release process
- Bump version in
setup.cfg
. - Add a commit "Release vX.Y.Z".
- Make sure checks still pass.
- Draft a new release with a tag name "X.Y.Z" and describe changes which involved in the release.
- Publish the release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flake8-printf-formatting-1.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f9e1308ac290356e4b271d4f26adfc3f9165680a7b6c221503b0f3e155a2784 |
|
MD5 | a214263ea5a888d87db7a8a9508c4c88 |
|
BLAKE2b-256 | 67838ce88e9dfb6b3eb100bb7535ebddc09b26a7027251ff0d4d9ea79c55958a |
Hashes for flake8_printf_formatting-1.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d908ffabdf08581043a50572744fd60563d82386630b0335445894120089d2df |
|
MD5 | 95edc2f0b6dc30b09976b3c29814d06d |
|
BLAKE2b-256 | e2f2ec11ecb58b368c4ff894286cf09564c34d36bd43df6822ee1c2f8825a2fd |