methoddispatch provides a decorator similar to `functools.singledispatch` but specifically designed for dispatching class methods based on the type of their arguments. It extends Python's built-in single dispatch functionality to work seamlessly within classes, supporting different implementations for various argument types. The current version is 5.0.1, with an irregular release cadence driven by feature enhancements and Python version compatibility.
pip install methoddispatchVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a class method with the `@methoddispatch` decorator and register different implementations for specific argument types. The generic `process` method serves as the fallback, while `int`, `str`, and `list` types have specialized implementations.
Refactor any plain functions using `methoddispatch` into class methods, or switch to `functools.singledispatch` for non-method functions.
Update your registration calls from `register(MyClass.method, type)` to `MyClass.method.register(type)`.
Be aware that generic type hints are treated as their base type for dispatch. If you need to differentiate between, say, `list[int]` and `list[str]`, you'll need to implement additional runtime checks within your `list` handler.
No dependency data recorded yet.