wemake-python-styleguide
wemake-python-styleguide is an extremely strict and opinionated Python linter, acting as a flake8 plugin and a companion to ruff. It aims to enforce consistent, maintainable, and less complex code, often surpassing standard PEP8 checks with its extensive rule set. The library is actively maintained with frequent minor releases, currently at version 1.6.1, and supports Python 3.10 and newer.
Common errors
-
C101 Coding magic comment not found
cause The Python file is missing a coding magic comment (e.g., `# -*- coding: utf-8 -*-`) at the top, which wemake-python-styleguide enforces.fixAdd `# -*- coding: utf-8 -*-` (or similar) as the first or second line of your Python files. -
C0304 Final newline missing
cause The linter detected that a file does not end with a newline character, a common PEP8 violation.fixEnsure all Python files end with a single newline character. Most IDEs can be configured to do this automatically on save. -
WPS214 Too many methods in a class (7 > 6)
cause The linter is enforcing a strict maximum number of methods per class (default 6), indicating potential violation of the Single Responsibility Principle.fixRefactor the class to reduce the number of methods, often by extracting related functionality into smaller helper classes or functions. Adjust the `max-methods` option in your `flake8` configuration if the default is too restrictive for your project. -
WPS210 Too many local variables (5 > 4)
cause A function or method exceeds the maximum allowed number of local variables (default 4), suggesting excessive complexity or too many responsibilities.fixRefactor the function into smaller, more focused units, or use data structures to group related variables. Adjust the `max-local-variables` option in your `flake8` configuration if the default is too restrictive. -
flake8: error: unrecognized arguments: --select=WPS
cause wemake-python-styleguide is installed, but flake8 is not detecting the 'WPS' selection option, likely because `flake8` itself is not installed or incorrectly configured, or `--select=WPS` is not the first argument when used with other flake8 arguments.fixEnsure `flake8` is installed (`pip install flake8`). Always specify `--select=WPS` directly after `flake8` if using it from the command line, or configure `select = WPS` in your `setup.cfg` or `pyproject.toml` under the `[flake8]` section.
Warnings
- breaking Version 1.0.0 introduced a significant breaking change by shifting to 'ruff compatibility'. Many rules previously handled by wemake-python-styleguide (and its internal flake8 plugins) were removed and are now expected to be covered by ruff. Users must integrate ruff into their workflow alongside flake8.
- gotcha wemake-python-styleguide is exceptionally strict and opinionated. New users will almost certainly encounter a large number of violations, even on well-written code, and will need to carefully configure ignored rules in `setup.cfg` or `pyproject.toml`.
- gotcha The complete linting experience now relies on running *both* `ruff` and `flake8 --select=WPS`. Simply running `flake8` without `ruff` (or without `--select=WPS`) will result in an incomplete set of checks and missed violations.
- deprecated Many specific WPS violation codes were removed in v1.0.0 because their checks are now handled by ruff or pylint. Relying on these old codes in configurations will no longer have an effect.
- gotcha The linter actively discourages excessive use of `# noqa` comments. The `WPS402` rule will flag modules with too many such comments, indicating potential issues with code quality or over-ignoring rules.
Install
-
pip install wemake-python-styleguide
Imports
- CLI tool
wps explain <code>
- flake8 integration
import wemake_python_styleguide
flake8 --select=WPS .
Quickstart
pip install wemake-python-styleguide flake8 ruff # --- pyproject.toml --- # [tool.ruff] # line-length = 88 # Or your preferred length # target-version = "py310" # # [tool.flake8] # select = "WPS" # max-complexity = 10 # max-line-length = 88 # Run ruff first for formatting and many common lints ruff format . ruff check . # Then run wemake-python-styleguide specific checks via flake8 flake8 --select=WPS .