A flake8 extension that checks classes attributes order
Low maintenance activity. Last release 20 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install flake8-class-attributes-orderflake8-class-attributes-order
An extension for flake8 to report on wrong class attributes order and class level logic.
The validator can extract class attribute type: docstring, property,
nested class, GLOBAL_VAR, etc.
If django model fields are detected, the validator can detect,
if the field is link to another table (foreign key, generic key, etc)
or not.
After resolving each attribute type, validator checks attributes order.
Default configuration checks for the following order of attributes:
__new____init____post_init__- other magic methods
@property@staticmethod@classmethod- other methods
- protected methods
- private methods
If the order is broken, validator will report on it.
Besides methods, the validator checks other attributes methods: docstrings, nested classes, constants, attributes, and so on.
Also validator checks, if class has no class level logic and report if any. Here is an example:
class PhoneForm(forms.Form):
phone = forms.CharField(17, label='Телефон'.upper())
# this should happen in __init__!
phone.widget.attrs.update({'class': 'form-control phone'})
Installation
pip install flake8-class-attributes-order
Configuration
Strict mode
There is another preconfigured order that is more strict on private subtypes: