The flake8_celery_bind_checker is a Flake8 plugin designed to ensure that Celery task functions are correctly defined with respect to the bind=True parameter. Specifically, it checks that:
- Functions decorated with
@shared_task(bind=True)must haveselfas their first argument. - Functions decorated with
@shared_task(bind=False)or without thebindparameter should not haveselfas their first argument.
These checks help maintain consistency and prevent common errors in defining Celery tasks.
To install flake8_celery_bind_checker from GitHub, you can use pip:
pip install git+https://github.com/eprikazc/flake8_celery_bind_checker.git@main
Alternatively, if you have access to the source code, navigate to the plugin directory and run:
pip install .
Once installed, flake8_celery_bind_checker will automatically be included when you run Flake8. To check your Python files, simply use:
flake8 your_project_directory/
If you are using a virtual environment, make sure flake8 and flake8_celery_bind_checker are installed within the same environment.
This plugin defines the following error codes:
- CBL001: Celery task with
bind=Truemust haveselfas its first argument. This error is raised whenbind=Trueis specified, but the first parameter is notself. - CBL002: Celery task without
bind=Trueor withbind=Falseshould not haveselfas its first argument. This error is raised whenbind=Trueis not specified, orbind=Falseis explicitly stated, and yet the first parameter isself.
Contributions to flake8_celery_bind_checker are welcome! Please feel free to fork the repository, make changes, and submit pull requests. If you find any issues or have suggestions for improvements, please open an issue in the repository.
This project is licensed under the MIT License - see the LICENSE file for details.