Overloading

0.5.0 · abandoned · verified Thu Apr 16

Overloading.py is a Python 3 library that provides function and method dispatching based on the types and number of runtime arguments. When an overloaded function is called, it compares the arguments supplied to available signatures and invokes the implementation that provides the most accurate match. The library's current version is 0.5.0, released in April 2016, suggesting a low or inactive release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to define multiple implementations of a function `biggest` using the `@overload` decorator. The library automatically dispatches to the correct implementation based on the runtime type of the `items` argument.

from collections.abc import Iterable
from overloading import overload

@overload
def biggest(items: Iterable[int]):
    return max(items)

@overload
def biggest(items: Iterable[str]):
    return max(items, key=len)

print(biggest([2, 0, 15, 8, 7]))
print(biggest(['a', 'abc', 'bc']))

view raw JSON →