This release is a pre-release and may not be stable for production use.
📟🔃 Unter
A Python module of decorators to allow base classes to selectively enforce their primacy even in the face of derived classes overriding implementations.
Overview
The unter module provides a set of decorators that can be applied to the base classes and its methods in order to ensure that calls of a method overridden in a derived class nevertheless invoke the base class implementation instead.
Normal Python method resolution order resolves the most-overridden method first when a call is made, and the ability for base classes to provide a common frame around an implementation customisable by derived classes is only achievable through either the explicit use of super(), or via template functions.
With unter, the base class can break the normal method resolution order and enforce its own implementation to be called first, while leaving the derived class to visually appear as-if to override the base class method (instead of _*_impl-style methods).
Installation
pip install unter
Quick-start
Current, Pythonic way of doing things
class Base:
def method(self):
print("Base.method() called")
self._method() # Calls the derived class method
print("Base.method() over!")
def _method(self):
print("Base._method() - not overridden")
class Derived(Base):
def _method(self):
print("Derived._method() - overridden")
# Whoops, should never do this by accident, otherwise, the implementation
# would break!
# def method(self):
# ...
>>> Base().method()
Base.method() called
Base._method() - not overridden
Base.method() over!
>>> Derived().method()
Base.method() called
Derived._method() - overridden
Base.method() over!
Basic decoration and primacy
from unter import unter
@unter.enable
class Base:
@unter.attorney
def method(self) -> int:
print("Base.method() called")
i = 1 + unter().method()
print("Base.method() over!", i)
return i
class Derived:
def method(self) -> int:
print("Derived.method() called")
i = 4
print("Derived.method() over!", i)
return i
>>> print(Derived().method())
Base.method() called
Derived.method() called
Derived.method() over! 4
Base.method() over! 5
5
Why?
unter is a highly specialised tool to invert the normal method resolution behaviour of class hierarchies. Specialised tools are things that one needs rarely, but when they are needed, they are needed badly.
Metadata
Release files for unter 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unter-0.1.0a1.tar.gz | 12.9 kB | Without provenance | Details for unter-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unter-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for unter-0.1.0a1-py3-none-any.whl |
Total release size: 27.2 kB
Release files / unter-0.1.0a1.tar.gz
| Download URL | unter-0.1.0a1.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35a053c68a1d9aff9dcba6aa84bb3378deaa876c994c01b5163bc6ccbe70122e
|
|
BLAKE2b-256 checksum How to use checksums |
22e4058c6545bf3da9f3433f5eafa1663c20fbcbe5fd378705a12227ddfa66e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / unter-0.1.0a1-py3-none-any.whl
| Download URL | unter-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc99a84b38e01e703f5dc7b96b6e04406f9f0c94827df7483ebac9ed1f4ed31e
|
|
BLAKE2b-256 checksum How to use checksums |
8b0ca2d3f6e7fddb7715fafb74096e730fd15cd8aa06b77152e8ff74ec272b90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for unter 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.