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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11cf2b4f574802d609c1cd146589d31d975c75a6a4f71b1b5e086c624526f504 |
|
MD5 | 584391189ee1b1df2c8c3791e4f510a0 |
|
BLAKE2b-256 | a51aa7f369df4e033e5941faf4ba9c96aa892284262c3b00b76e72ae7ce42f1a |
Close
Hashes for amulet_runtime_final-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 240bd1bca7ba85e8a953f0979ba0b35c639058d129e4004dbd8efb55130d463d |
|
MD5 | bf6fb6792a9ff7deb0d11acc944d85ab |
|
BLAKE2b-256 | b3f0fc0687a0d9398fffea5f3fc21464ecfd515e897f7cb0ae7c4c6fce48b81d |