flake8-simplify

0.30.0 · active · verified Wed Apr 15

flake8-simplify is a plugin for the Flake8 linter that identifies and suggests simplifications for Python code. It helps developers improve code readability, reduce complexity, and catch common minor mistakes by checking for patterns that can be written more concisely. The current version is 0.30.0, and it maintains a consistent release cadence with regular updates introducing new rules and maintenance fixes.

Warnings

Install

Imports

Quickstart

To quickly use flake8-simplify, first ensure you have `flake8` installed, then install `flake8-simplify`. Create a Python file with code that can be simplified, and then run the `flake8` command on that file. The output will show any identified simplifications with their respective SIM codes.

import os

# SIM201: Use 'a != b' instead of 'not a == b'
def bad_comparison(a, b):
    if not a == b:
        return True
    return False

# SIM101: Multiple isinstance-calls which can be merged into a single call
def bad_instance(obj):
    if isinstance(obj, int) or isinstance(obj, float):
        return "Number"
    return "Other"

# To run flake8-simplify:
# 1. Save the code above as example.py
# 2. Open your terminal in the same directory
# 3. Run: pip install flake8 flake8-simplify
# 4. Run: flake8 example.py

view raw JSON →