A decorator to automatically detect mismatch when overriding a method.
Project description
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
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
Project details
Release history Release notifications | RSS feed
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.5.tar.gz
(4.3 kB
view details)
File details
Details for the file overrides-2.5.tar.gz.
File metadata
- Download URL: overrides-2.5.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a35fd3a23071549790731654ea28490bb741e353f2d4b829b7202ef14e0f28ef
|
|
| MD5 |
0d4c475ae83b4c209eed22eb737f2b51
|
|
| BLAKE2b-256 |
8ba00d4a9dcd28de9bf263e9436b5876ba199cc4e4a19d0dc4e85eed657b1b77
|