Registry / serialization / overloading

overloading

JSON →
library0.5.0pypypi✓ verified 84d ago

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.

pip install overloading
INSTALL
IMPORT
SIG · OVERLOADING
O
overloading
serializationpythonv0.5.0
Install
1.9s avg
Import
31ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.032s · 67.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.9s · import 0.030s · 18MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

overload
from overloading import overload
from typing import overload
The `typing.overload` decorator is for static type checking only and does not provide runtime dispatch like this library.

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']))
Debug
Known issues
breakingBetween v0.4 and v0.5, the treatment of `classmethod` and `staticmethod` was harmonized. These decorators must now appear *after* the `@overload` directive.
fix
Ensure `@classmethod` or `@staticmethod` is placed below `@overload`:
```python
@overload
@classmethod
def my_method(cls, arg: int):
    ...
```
affects: >=0.5.0
gotchaPython does not have native function overloading; the `overloading` library provides runtime dispatch based on argument types. Do not confuse it with `typing.overload`, which is solely for static type checkers and does not affect runtime behavior.
fix
Always import `overload` from the `overloading` library (`from overloading import overload`) for runtime dispatch. If you only need type-checker hints without runtime behavior modification, use `from typing import overload` (Python 3.5+).
affects: All versions
gotchaThe library's last release was in 2016, indicating it is no longer actively maintained. While functional, it might not fully leverage newer Python features or integrate seamlessly with modern type-hinting patterns as well as alternatives like `functools.singledispatch` (for single-argument dispatch) or `multimethod` for more active maintenance.
fix
Consider `functools.singledispatch` for single-argument type-based dispatch (standard library, Python 3.4+) or `multimethod` for a more actively maintained third-party multiple-dispatch solution if long-term support and modern features are critical.
affects: All versions
Errors
Common errors & fixes
TypeError: 'staticmethod' object is not callable
Incorrect decorator order where `@staticmethod` or `@classmethod` is placed before `@overload`.
fix
Due to a breaking change in v0.5, place `@staticmethod` or `@classmethod` *after* the `@overload` decorator.
```python
@overload
@staticmethod
def my_method(arg: str):
    return f'Static method with {arg}'
```
overloading.errors.NoApplicableOverload: No applicable overload found for my_function(<class 'float'>)
An overloaded function was called with argument types for which no matching `@overload` implementation has been defined.
fix
Define an `@overload` for the specific argument types being passed, or provide a more general overload (e.g., using `object`) that can act as a fallback. Ensure type hints accurately reflect expected inputs.
overloading.errors.AmbiguityError: Ambiguous overloads for process_data(<class 'int'>, <class 'int'>)
The dispatcher found multiple `@overload` implementations that could equally match the given runtime arguments, leading to an ambiguous choice.
fix
Refine the type hints in your `@overload` definitions to be more specific, ensuring that for any given set of arguments, only one overload provides the 'most accurate match'. This often means adding more specific type hints to resolve overlaps.
Upgrade
Version history
0.5.0latest on PyPI · released Apr 15, 2016
Audit
Dependencies
typingoptionalProvides extended type hints, optional for Python versions older than 3.5.
Agent activity
2 hits · last 30 days
node
2
Resources
overloading — pip install overloading · libregistry