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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8507be162acefe94f37427011fee0def4fb72c2f62dbaf6f633f2cd2a3cddfe |
|
MD5 | 72c9bf19a077bf5b0eda3382cc1484c2 |
|
BLAKE2b-256 | f97c1a5f3c6e8e4df1d9042799c948d44ea6a6cc4419243419db6dc17def1726 |
Close
Hashes for amulet_runtime_final-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9efadc0c1c31ae5c26a3023c98e9b484d03ed33e51fe8303e935c4ba50379fa6 |
|
MD5 | c6fc1b46ff695b1e298255c95a837c1c |
|
BLAKE2b-256 | f73e6156d9f07057d2fe937ca2db6af865cf26fe79ef1d27ce57eca0e4b12365 |