Registry / testing / flake8-class-attributes-order

flake8-class-attributes-order

JSON →
library0.3.0pypypiunverified

An extension for Flake8 that enforces a consistent order for attributes within Python classes. It analyzes various attribute types, including docstrings, properties, methods, nested classes, and constants, and can also detect Django model fields. The current version is 0.3.0, and it maintains an active release cadence with regular updates.

pip install flake8-class-attributes-order
INSTALL
IMPORT
SIG · FLAKE8-CLASS-ATTRI
F
flake8-class-attributes-order
testingpythonv0.3.0
Install
1.9s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.9s · import 0.000s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
Install 'flake8-class-attributes-order'; it's automatically discovered by Flake8.
Flake8 plugins are typically discovered and loaded automatically upon installation; direct Python 'import' statements for the plugin's checks are not used in user code.

To use `flake8-class-attributes-order`, first install it. Then, run `flake8` as you normally would. The plugin automatically integrates. You can configure the order or enable strict mode via a configuration file such as `setup.cfg` or `.flake8`.

import os # Create a dummy python file for flake8 to check with open('my_module.py', 'w') as f: f.write("""class MyClass: FOO = 1 def __init__(self): self.bar = 2 def method_a(self): pass """) # Create a flake8 configuration file to enable strict mode (optional, but good for demo) with open('setup.cfg', 'w') as f: f.write("[flake8]\nuse_class_attributes_order_strict_mode = True\n") # Run flake8. Note: flake8's exit code is non-zero if errors are found. # We use os.system for demonstration; in a real CI, you'd just run 'flake8'. print("Running flake8 without strict mode (default order):") os.system("flake8 my_module.py") print("\nRunning flake8 with strict mode (via setup.cfg):") os.system("flake8 my_module.py") # Clean up os.remove('my_module.py') os.remove('setup.cfg')
Debug
Known issues
breakingVersion 0.3.0 dropped support for Python 3.8. Ensure your environment uses Python 3.9 or newer.
fix
Upgrade to Python 3.9 or a later compatible version.
affects: >=0.3.0
breakingVersion 0.2.0 dropped support for Python 3.7. Ensure your environment uses Python 3.8 or newer to use this version.
fix
Upgrade to Python 3.8 or a later compatible version.
affects: >=0.2.0, <0.3.0
gotchaTo enable stricter attribute ordering checks, set `use_class_attributes_order_strict_mode = True` in your `flake8` configuration file (e.g., `setup.cfg`, `tox.ini`, or `.flake8`).
fix
Add `[flake8]\nuse_class_attributes_order_strict_mode = True` to your project's `setup.cfg` or `.flake8` file.
affects: All
gotchaThe plugin introduces specific error codes, such as CCE001 ('Wrong class attributes order') and CCE002 ('Class has class level logic'). If you wish to ignore these, you must explicitly add them to the `ignore` list in your Flake8 configuration.
fix
Add `ignore = CCE001,CCE002` (or specific codes) under the `[flake8]` section of your configuration file.
affects: All
gotchaCustom attribute orders can be defined using the `class_attributes_order` setting in the Flake8 configuration file. The default order is specific, and deviations will be reported.
fix
Refer to the documentation for the default order and define `class_attributes_order` in your `[flake8]` config section to match your desired sequence.
affects: All
Upgrade
Version history
0.3.0latest on PyPI · released Mar 20, 2025
Audit
Dependencies
flake8requiredThis is a plugin for Flake8, so Flake8 itself is required to run the checks.
pythonrequiredRequires Python 3.9 or newer.
Agent activity
6 hits · last 30 days
node
6
Resources
flake8-class-attributes-order — pip install flake8-class-attributes-order · libregistry