Skip to main content
https://img.shields.io/pypi/v/overrides.svg http://pepy.tech/badge/overrides

A decorator to automatically detect mismatch when overriding a method. See http://stackoverflow.com/questions/1167617/in-python-how-do-i-indicate-im-overriding-a-method

All checks are done when a class or a method is created and not when a method is executed or an instance of a class is created. This means that performance implications are minimal.

Note: Version 2.8.0 is the last one that supports Python 2.7. Versions after that work with Python >= 3.6.

Why explicit overrides?

Overrides without explicit indicator for them are weak. They leave room for problems that happen during the evolution of a codebase.

  1. (create) Accidental overriding in a subclass when a method to a superclass is added (or vice versa).

  2. (modify) Rename of a superclass method without subclass method rename (or vice versa).

  3. (delete) Deleting of a superclass method without detecting in subclass that the method is not anymore overriding anything (or vice versa).

These might happen for example when overriding a method in a module that does not live in your codebase, or when merging changes done by someone else to the codebase without having access to your subclass.

Installation

$ pip install overrides

Usage

from overrides import overrides

class SuperClass:

    def method(self):
        """This is the doc for a method and will be shown in subclass method too!"""
        return 2


class SubClass(SuperClass):

    @overrides
    def method(self):
        return 1

Enforcing usage

from overrides import EnforceOverrides, final, overrides

class SuperClass(EnforceOverrides):

    @final
    def method(self):
        """This is the doc for a method and will be shown in subclass method too!"""
        return 2

    def method2(self):
        """This is the doc for a method and will be shown in subclass method too!"""
        return 2

    @staticmethod
    def method3():
        """This is the doc for a method and will be shown in subclass method too!"""
        return 2


# THIS FAILS
class SubClass1(SuperClass):

    def method(self): # <-- overriding a final method
        return 1


# THIS FAILS
class SubClass2(SuperClass):

    def method2(self): # <-- @overrides decorator missing
        return 1


# THIS ONE IS OK
class SubClass3(SuperClass):

    @overrides
    def method2(self):
        return 1


# ENSURE THAT @classmethod AND @staticmethod ARE PLACED AT THE TOP
class SubClass4(SuperClass):

    @staticmethod
    @overrides
    def method3():
        return 1

Contributors

This project becomes a reality only through the work of all the people who contribute.

mkorpela, drorasaf, ngoodman90, TylerYep, leeopop, donpatrice, jayvdb, joelgrus, lisyarus, soulmerge, rkr-at-dbx, ashwin153

Metadata

Release files for overrides 4.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for overrides 4.1.1
File Size Uploaded
overrides-4.1.1.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for overrides 4.1.1
File Interpreter ABI Platform
overrides-4.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / overrides-4.1.1.tar.gz

Download URL overrides-4.1.1.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1782a897a70f38f3d4d42ac883941c5c32ace5ad07abe3293ce211d2279953d2
BLAKE2b-256 checksum
How to use checksums
3dc0af3507928e1845e5c03bc68d1ed62b744c6262378cdb2aef9c885ef700c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

Release files / overrides-4.1.1-py3-none-any.whl

Download URL overrides-4.1.1-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b685f3cb92d4d8f019c94462d46449798050891f3c3c77b8d4c892f5078498f4
BLAKE2b-256 checksum
How to use checksums
1308ffd2ebf3c1c5be9be493dcbdb250567e4b244953b061cad5c7f0160b28ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

Release history Release notifications | RSS feed

7.7.0

2 release files

7.6.0

2 release files

7.5.0

2 release files

7.4.0

2 release files

7.3.1

2 release files

7.3.0

2 release files

7.2.0

2 release files

7.1.0

2 release files

7.0.0

2 release files

6.5.0

2 release files

6.4.0

2 release files

6.3.0

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.1.2

2 release files

This release

4.1.1 This release

2 release files

4.1.0

2 release files

4.0.0

1 release file

3.1.0

1 release file

3.0.0

1 release file

2.8.0

1 release file

2.7.0

1 release file

2.6

1 release file

2.5

1 release file

2.4

1 release file

2.3

1 release file

2.2

1 release file

2.1

1 release file

2.0

1 release file

1.9

1 release file

1.8

2 release files

1.7

1 release file

1.6

1 release file

0.5

1 release file

0.4

2 release files

0.3

2 release files

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page