--- id: methoddispatch version: "5.0.1" license: BSD license_treatment: permissive maintenance: dormant --- # methoddispatch — singledispatch decorator for class methods. License: permissive · Maintenance: dormant · Downloads: 98.4K/mo ## What it is and what it does methoddispatch extends Python's functools.singledispatchmethod to allow subclasses to maintain independent dispatch tables. The standard library's singledispatchmethod (added in Python 3.8) shares a dispatch registry across all subclasses, preventing subclasses from overriding type handlers without affecting the parent class. This package solves that by providing a SingleDispatch mixin that gives each class its own registry copy. You decorate a method with @singledispatch and then register type-specific implementations using @method.register(type). When the method is called, it dispatches to the appropriate implementation based on the type of the first argument. Subclasses can extend or override the registry independently, and you can also register implementations at runtime via add_overload() or on individual instances. Type hints are supported for automatic type inference. Use it for: - Implement polymorphic behavior in class hierarchies where different subclasses need different type handlers without modifying parent dispatch tables. - Create generic data processors that handle multiple input types (int, str, list, etc.) with specialized logic for each. - Build plugin or strategy systems where handlers are registered by type and subclasses can add their own type handlers. - Write serializers or formatters that dispatch on object type to produce different output representations. - Develop type-aware method resolution in domain models where behavior depends on argument type rather than method name. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Adds single-dispatch method support to Python classes, allowing methods to dispatch on the type of their first argument with independent dispatch tables per subclass. Yes, if you need independent dispatch tables in class hierarchies. The package solves a real limitation of functools.singledispatchmethod and has no dependencies. Dormant maintenance is acceptable here—the feature is stable and unlikely to need updates. Install it for polymorphic method dispatch; avoid it if you only need single-dispatch functions (use functools.singledispatch instead). ## Install pip install methoddispatch uv add methoddispatch poetry add methoddispatch ## Installing methoddispatch Before you install: Low install friction with no runtime dependencies. Maintenance is dormant—last release was 2023-11-21 and no commits since then—but the package is stable and archived status is false, suggesting it is maintained as-is rather than abandoned. License in practice: BSD license is permissive, allowing commercial and private use with minimal restrictions; suitable for most projects. Quickstart: from methoddispatch import singledispatch, SingleDispatch class MyClass(SingleDispatch): @singledispatch def process(self, arg): print(arg) @process.register(int) def process_int(self, arg): print(f"int: {arg}") obj = MyClass() obj.process(42) # dispatches to process_int Verify before relying: - Whether the package works correctly with Python 3.12+ given the last release was 2023-11-21 and no explicit classifier for 3.12 is listed. - Performance characteristics when dispatch registries grow large or when used in high-throughput scenarios. ## Package facts - License: BSD (permissive) - Python support: unspecified - Install friction: low - Maintenance: dormant - Downloads: 98.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags single dispatch decorator methods, type-based method overloading, generic methods python, singledispatch for class methods, method dispatch by type, polymorphic method dispatch, method-dispatch, polymorphism [View on SkillFed](https://skillfed.io/packages/methoddispatch) · [View on PyPI](https://pypi.org/project/methoddispatch/)