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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amulet-runtime-final-1.1.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amulet_runtime_final-1.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file amulet-runtime-final-1.1.2.tar.gz.

File metadata

  • Download URL: amulet-runtime-final-1.1.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for amulet-runtime-final-1.1.2.tar.gz
Algorithm Hash digest
SHA256 a20d063a5c1b438e36290753ecf04e76d18843be04205c3b9cba35eb2d1b3cce
MD5 50c491d65228c984addfbb3a650267f1
BLAKE2b-256 8f3ff75a35328e1b396fab6e6995b53ed2007dc6e70c9eeda4eec95a0d7be82f

See more details on using hashes here.

File details

Details for the file amulet_runtime_final-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for amulet_runtime_final-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1739f32ce399e30cf63c223d3e1cdc9dcd2c52bdde36fb9879e2f88714aac7f6
MD5 5c2db84e0a4eb03db3683f4fd8c354c8
BLAKE2b-256 ceea5172c8003d2f22dc7f43718d18ef89f23dbba8308228857d10867cbb6316

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 files

1.1.1

2 files

1.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page