Skip to main content

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):
        ...

Metadata

Release files for amulet-runtime-final 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amulet-runtime-final 1.1.2
File Size Uploaded
amulet-runtime-final-1.1.2.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for amulet-runtime-final 1.1.2
File Interpreter ABI Platform
amulet_runtime_final-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / amulet-runtime-final-1.1.2.tar.gz

Download URL amulet-runtime-final-1.1.2.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a20d063a5c1b438e36290753ecf04e76d18843be04205c3b9cba35eb2d1b3cce
BLAKE2b-256 checksum
How to use checksums
8f3ff75a35328e1b396fab6e6995b53ed2007dc6e70c9eeda4eec95a0d7be82f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / amulet_runtime_final-1.1.2-py3-none-any.whl

Download URL amulet_runtime_final-1.1.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1739f32ce399e30cf63c223d3e1cdc9dcd2c52bdde36fb9879e2f88714aac7f6
BLAKE2b-256 checksum
How to use checksums
ceea5172c8003d2f22dc7f43718d18ef89f23dbba8308228857d10867cbb6316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page