Declare final Python classes and methods at runtime.
Project description
amulet-runtime-final
Declare final Python classes and methods at runtime.
This module provides a decorator based interface to declare final classes and methods that are enforced at runtime.
This module is inspired by and is compatible with typing.final
.
See PEP-591 for more details on this topic.
Installation
Python 3.6 or higher is required.
You can simply install this module from pip
.
python -m pip install amulet-runtime-final
Usage
The main component of this module is the final
decorator that
can be used to decorate classes and methods inside a class. As
such:
- Classes decorated with @final cannot be subclassed.
- Methods decorated with @final cannot be overriden in subclasses.
For example with classes:
from runtime_final import final
@final
class Foo:
...
class Bar(Foo): # Raises RuntimeError
...
And with methods:
from runtime_final import final
class Foo:
@final
def foo(self):
...
class Bar(Foo):
def foo(self): # Raises RuntimeError
...
And with other decorators:
from runtime_final import final
class Foo:
@final
@property
def foo(self):
...
@final
@staticmethod
def bar():
...
@final
@classmethod
def baz(cls):
...
class Bar(Foo):
@property
def foo(self): # Raises RuntimeError
...
@staticmethod
def bar(): # Raises RuntimeError
...
@classmethod
def baz(cls): # Raises RuntimeError
...
With property setters:
from runtime_final import final
class Foo:
@property
def foo(self):
...
# Note that the `final` decorator must only be applied to the last definition.
@final
@foo.setter
def foo(self, foo):
...
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
Built Distribution
Close
Hashes for amulet-runtime-final-1.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a20d063a5c1b438e36290753ecf04e76d18843be04205c3b9cba35eb2d1b3cce |
|
MD5 | 50c491d65228c984addfbb3a650267f1 |
|
BLAKE2b-256 | 8f3ff75a35328e1b396fab6e6995b53ed2007dc6e70c9eeda4eec95a0d7be82f |
Close
Hashes for amulet_runtime_final-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1739f32ce399e30cf63c223d3e1cdc9dcd2c52bdde36fb9879e2f88714aac7f6 |
|
MD5 | 5c2db84e0a4eb03db3683f4fd8c354c8 |
|
BLAKE2b-256 | ceea5172c8003d2f22dc7f43718d18ef89f23dbba8308228857d10867cbb6316 |