Skip to main content

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.0.1

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

Source distribution (sdist)

Source distribution for overfunc 0.0.1
File Size Uploaded Provenance Actions
overfunc-0.0.1.tar.gz 27.4 kB With provenance Details for overfunc-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for overfunc 0.0.1
File Interpreter ABI Platform Actions
overfunc-0.0.1-py3-none-any.whl Python 3 none any Details for overfunc-0.0.1-py3-none-any.whl

Total release size: 50.1 kB

Release files / overfunc-0.0.1.tar.gz

Download URL overfunc-0.0.1.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
19fb2eb0a339f485f39c7829b43e11c70ef54fc036d6b1b93b7be2a1f7f762a5
BLAKE2b-256 checksum
How to use checksums
db5dfc7024f0418f774561f3c9a8c363b25b733486be6d65f3ae3040fbe79d70
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 21, 2026.

Transparency log

Release files / overfunc-0.0.1-py3-none-any.whl

Download URL overfunc-0.0.1-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b29b3f85d5404ad26ca479d6b36bb2a9d7dee7054bb213fb1d9d85649e89d631
BLAKE2b-256 checksum
How to use checksums
824a5043e5533499e5cc50267020c7565fc3e9f2a818833a73c7c9aff92f7a83
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 21, 2026.

Transparency log

Security for overfunc 0.0.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.

Select from 2 files

Attestation for overfunc-0.0.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 21, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

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