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.1b1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 183dc3485e339a7404f2b7e5108c75b89c00b2e8d7ebb2037b7a173edc1b84fd |
|
MD5 | a6ba40f453e3fc2247f053bad2f8e0b4 |
|
BLAKE2b-256 | 13499781de12682add0d8bb60bbc3d1011e957d649d5da089d6edf5179fec23c |
Close
Hashes for amulet_runtime_final-1.1.1b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73326cdcf1aa4f4348201dcec929e72381074150ea1bf3198bb2bd9db49f29e7 |
|
MD5 | b15a5d41785633e59373adc1796d0a00 |
|
BLAKE2b-256 | f90a5754908ed11ed9620d752dc910b0185af3bd68e4d0a8b1b3b44050eb42e3 |