Skip to main content
https://api.travis-ci.org/mkorpela/overrides.svg https://coveralls.io/repos/mkorpela/overrides/badge.svg 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 performace implications are minimal.

Installation

$ pip install overrides

Usage

from overrides import overrides

class SuperClass(object):

    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

    def method3(self):
        """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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

overrides-2.8.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file overrides-2.8.0.tar.gz.

File metadata

  • Download URL: overrides-2.8.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.3

File hashes

Hashes for overrides-2.8.0.tar.gz
Algorithm Hash digest
SHA256 2ee4055a686a3ab30621deca01e43562e97825e29b7993e66d73f287d204e868
MD5 c5edcf845e0d43c7fcc4925a5b48ecbd
BLAKE2b-256 72ddac49f9c69540d7e09210415801a05d0a54d4d0ca8401503c46847dacd3a0

See more details on using hashes here.

Release history Release notifications | RSS feed

7.7.0

2 files

7.6.0

2 files

7.5.0

2 files

7.4.0

2 files

7.3.1

2 files

7.3.0

2 files

7.2.0

2 files

7.1.0

2 files

7.0.0

2 files

6.5.0

2 files

6.4.0

2 files

6.3.0

2 files

6.2.0

2 files

6.1.0

2 files

6.0.1

2 files

6.0.0

2 files

5.0.1

2 files

5.0.0

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.0

1 file

3.1.0

1 file

3.0.0

1 file

This release

2.8.0 This release

1 file

2.7.0

1 file

2.6

1 file

2.5

1 file

2.4

1 file

2.3

1 file

2.2

1 file

2.1

1 file

2.0

1 file

1.9

1 file

1.8

2 files

1.7

1 file

1.6

1 file

0.5

1 file

0.4

2 files

0.3

2 files

0.2

1 file

0.1

1 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