flake8-pep3101

raw JSON →
3.0.0 verified Mon Apr 27 auth: no python

A flake8 plugin that checks for use of old-style % string formatting, enforcing PEP 3101 (str.format and f-strings). Current version 3.0.0, supports Python >=3.10. Maintained on GitHub.

pip install flake8-pep3101
error flake8: P101 not found
cause Plugin not installed or not recognized by flake8.
fix
Run 'pip install flake8-pep3101' and ensure flake8 is installed in the same environment.
error ModuleNotFoundError: No module named 'flake8_pep3101'
cause Trying to import the plugin directly in code instead of using it as a flake8 plugin.
fix
Do not import manually; just install the package and run 'flake8'.
error P101 warning for modulo in bash-like string
cause Plugin might flag '%' in strings that are not Python formatting but intended as literal percent (e.g., SQL queries, URLs).
fix
Use '%%' for literal percent or use # noqa: P101.
gotcha The plugin only detects '%' formatting, not 'Template' strings or other patterns.
fix Use str.format() or f-strings as per PEP 3101.
gotcha The plugin may produce false positives when '%' is used in non-string contexts (e.g., modulo operator) or inside comments.
fix Review warnings manually or use # noqa: P101 to suppress if legitimate.
deprecated Old versions used import from flake8_pep3101; plugin auto-loads via flake8's built-in plugin discovery.
fix Upgrade to 3.0.0. No code changes needed.

Create a sample Python file with old-style % formatting and run flake8 to see the P101 warning.

# Create a file with old-style formatting
code = "name = 'world'; print('Hello %s' % name)"
with open('test.py', 'w') as f:
    f.write(code)

# Run flake8
import subprocess
result = subprocess.run(['flake8', 'test.py'], capture_output=True, text=True)
print(result.stdout)
# Expected: test.py:1:1: P101 % string formatting