Skip to content

blablatdinov/flake8-override

Repository files navigation

flake8-override

Build Status codecov Python Version wemake-python-styleguide

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

Installation

You can install flake8-override via pip:

pip install flake8-override

Usage

To 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_directory

Example

Input code

class Dog:

    def sound(self):
        print('bark')

Expected code

from typing import Protocol, override

class Animal(Protocol):

    def sount(self): ...

class Dog(Animal):

    @override
    def sound(self):
        print('bark')

Rationale

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.

License

MIT

Credits

This project was generated with wemake-python-package. Current template version is: 864a62ecb432655249d071e263ac51f053448659. See what is updated since then.

About

Flake8 plugin designed to enforce a coding standard where every method in a class must have the "typing.override" decorator. This ensures that all public methods implement their counterparts from an interface, promoting better design practices

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors