overfunc
overfunc dispatches a call to one of several registered implementations.
Use MultiFunc with explicit validators, TypedFunc with argument
annotations, or comparison and version decorators for common dispatch rules.
Installation
pip install overfunc
Python 3.9 or newer is required.
MultiFunc
Create a dispatcher with a representative function, then register
implementations with validators. Validators receive the same arguments as the
call and return True when their implementation should be selected.
from overfunc import MultiFunc
@MultiFunc
def describe(value: object) -> str:
raise NotImplementedError
@describe.register(lambda value: isinstance(value, int))
def describe_integer(value: object) -> str:
return f"integer: {value}"
@describe.register(lambda value: isinstance(value, str))
def describe_string(value: object) -> str:
return f"string: {value}"
print(describe(42)) # integer: 42
print(describe("hello")) # string: hello
When multiple validators match, implementations registered with a priority are checked first, from highest to lowest. Implementations without a priority are checked afterward in registration order.
@describe.register(
lambda value: isinstance(value, int) and value > 0,
priority=10,
)
def describe_positive_integer(value: object) -> str:
return f"positive integer: {value}"
If no validator matches, the dispatcher raises MultiFuncError.
TypedFunc
TypedFunc adds a validator that checks whether the call fits the registered
implementation's signature and whether annotated arguments match their types.
Arguments without annotations are not type-checked.
from overfunc import TypedFunc
@TypedFunc
def describe(value: object) -> str:
raise NotImplementedError
@describe.register()
def describe_integer(value: int) -> str:
return f"integer: {value}"
@describe.register()
def describe_string(value: str) -> str:
return f"string: {value}"
@describe.register(
lambda value: value > 0,
priority=10,
)
def describe_positive_integer(value: int) -> str:
return f"positive integer: {value}"
print(describe(-2)) # integer: -2
print(describe(42)) # positive integer: 42
print(describe("hello")) # string: hello
Additional validators can be passed to TypedFunc.register(); they must all
return True for the implementation to be selected.
The runtime type checker supports ordinary classes, unions, Literal, and
element checks for annotated lists, sets, dictionaries, and tuples. Runtime
checking cannot enforce every constraint expressible by Python's typing
system.
CompareDecorator
Use CompareDecorator to extract values from call arguments and register
implementations for comparison ranges.
from overfunc import CompareDecorator
@CompareDecorator(amount=lambda amount: amount)
def price_band(amount: float) -> str:
raise NotImplementedError
@price_band.register().lt(amount=0)
def credit(amount: float) -> str:
return "credit"
@price_band.register().ge(amount=0).lt(amount=100)
def regular(amount: float) -> str:
return "regular"
@price_band.register().ge(amount=100)
def bulk(amount: float) -> str:
return "bulk"
print(price_band(-5)) # "credit"
print(price_band(25)) # "regular"
print(price_band(125)) # "bulk"
The keyword in each comparison (here, amount) refers to a configured
getter. Getters can also be created from argument attributes with
CompareDecorator().with_attr("value").
VersionedDecorator
Use VersionedDecorator to select an implementation for a version interval.
The upper bound is exclusive.
from overfunc import VersionedDecorator
@VersionedDecorator(version=lambda version: version)
def decode(version: tuple[int, int]) -> str:
raise NotImplementedError
@decode.register().for_version(initial=(1, 0), final=(2, 0))
def decode_v1(version: tuple[int, int]) -> str:
return "v1 format"
@decode.register().for_version(initial=(2, 0))
def decode_v2(version: tuple[int, int]) -> str:
return "v2 format"
print(decode((1, 5))) # "v1 format"
print(decode((2, 1))) # "v2 format"
Version decorators can also use named argument attributes and tags to combine version and other comparison rules.
Metadata
Release files for overfunc 0.1.1
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 |
|---|---|---|---|---|
| overfunc-0.1.1.tar.gz | 27.4 kB | With provenance | Details for overfunc-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| overfunc-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for overfunc-0.1.1-py3-none-any.whl |
Total release size: 49.8 kB
Release files / overfunc-0.1.1.tar.gz
| Download URL | overfunc-0.1.1.tar.gz |
|---|---|
| Size | 27.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8157b91d53ed042ec96e7fd85d506619c592170970faefe3991f49a73425dd54
|
|
BLAKE2b-256 checksum How to use checksums |
bb76537b89e03c633146562731426cd586d56e28093442aeba551da8bbbb496c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / overfunc-0.1.1-py3-none-any.whl
| Download URL | overfunc-0.1.1-py3-none-any.whl |
|---|---|
| Size | 22.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb4f868c37486d854662bc83134ec94e09ade1bba799e91448171eb1b28f9b27
|
|
BLAKE2b-256 checksum How to use checksums |
eac7219475f1c281d2c3897ce8b911ec9cbe37c27d55bcdca566ecfecb126c63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for overfunc 0.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for overfunc-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA 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.