{"id":9165,"library":"overloading","title":"Overloading","description":"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.","status":"abandoned","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/bintoro/overloading.py","tags":["overloading","dispatch","function","decorator","type hinting","polymorphism"],"install":[{"cmd":"pip install overloading","lang":"bash","label":"Install core library"},{"cmd":"pip install typing","lang":"bash","note":"Required if using extended type hints on Python versions prior to 3.5","label":"Install typing module for Python < 3.5 (optional)"}],"dependencies":[{"reason":"Provides extended type hints, optional for Python versions older than 3.5.","package":"typing","optional":true}],"imports":[{"note":"The `typing.overload` decorator is for static type checking only and does not provide runtime dispatch like this library.","wrong":"from typing import overload","symbol":"overload","correct":"from overloading import overload"}],"quickstart":{"code":"from collections.abc import Iterable\nfrom overloading import overload\n\n@overload\ndef biggest(items: Iterable[int]):\n    return max(items)\n\n@overload\ndef biggest(items: Iterable[str]):\n    return max(items, key=len)\n\nprint(biggest([2, 0, 15, 8, 7]))\nprint(biggest(['a', 'abc', 'bc']))\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `@classmethod` or `@staticmethod` is placed below `@overload`:\n```python\n@overload\n@classmethod\ndef my_method(cls, arg: int):\n    ...\n```\n","message":"Between v0.4 and v0.5, the treatment of `classmethod` and `staticmethod` was harmonized. These decorators must now appear *after* the `@overload` directive.","severity":"breaking","affected_versions":">=0.5.0"},{"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+).","message":"Python 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Due to a breaking change in v0.5, place `@staticmethod` or `@classmethod` *after* the `@overload` decorator.\n```python\n@overload\n@staticmethod\ndef my_method(arg: str):\n    return f'Static method with {arg}'\n```","cause":"Incorrect decorator order where `@staticmethod` or `@classmethod` is placed before `@overload`.","error":"TypeError: 'staticmethod' object is not callable"},{"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.","cause":"An overloaded function was called with argument types for which no matching `@overload` implementation has been defined.","error":"overloading.errors.NoApplicableOverload: No applicable overload found for my_function(<class 'float'>)"},{"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.","cause":"The dispatcher found multiple `@overload` implementations that could equally match the given runtime arguments, leading to an ambiguous choice.","error":"overloading.errors.AmbiguityError: Ambiguous overloads for process_data(<class 'int'>, <class 'int'>)"}]}