flake8-override is a Flake8 plugin designed to enforce a coding standard where every method in a class must have the @override decorator. This ensures that all public methods implement their counterparts from an interface, promoting better design practices, easier mocking in unit tests, and simpler extension via decoration.
Seven Virtues of a Good Object. Part 2
You can install flake8-override via pip:
pip install flake8-overrideTo use flake8-override, simply include it in your Flake8 configuration. You can run Flake8 as usual, and the plugin will check for the presence of the @override decorator on each method.
flake8 your_code_directoryclass Dog:
def sound(self):
print('bark')from typing import Protocol, override
class Animal(Protocol):
def sount(self): ...
class Dog(Animal):
@override
def sound(self):
print('bark')The primary motivation for this plugin is to ensure that objects adhere to contracts as specified by interfaces. This has two main benefits:
- Easier Mocking in Unit Tests: Objects that work by contract are easier to mock in unit tests because their behavior is predictable and defined by interfaces.
- Simpler Extension via Decoration: Objects designed with clear contracts are easier to extend and decorate, promoting better software design and maintenance.
This project was generated with wemake-python-package. Current template version is: 864a62ecb432655249d071e263ac51f053448659. See what is updated since then.