|
|
@ -8,7 +8,8 @@ try: |
|
|
|
except ImportError: |
|
|
|
from functools import singledispatch, update_wrapper |
|
|
|
class singledispatchmethod: |
|
|
|
"""Single-dispatch generic method descriptor. |
|
|
|
""" |
|
|
|
Single-dispatch generic method descriptor. |
|
|
|
Supports wrapping existing descriptors and handles non-descriptor |
|
|
|
callables as instance methods. |
|
|
|
""" |
|
|
@ -16,12 +17,13 @@ except ImportError: |
|
|
|
def __init__(self, func): |
|
|
|
if not callable(func) and not hasattr(func, "__get__"): |
|
|
|
raise TypeError(f"{func!r} is not callable or a descriptor") |
|
|
|
|
|
|
|
|
|
|
|
self.dispatcher = singledispatch(func) |
|
|
|
self.func = func |
|
|
|
|
|
|
|
def register(self, cls, method=None): |
|
|
|
"""generic_method.register(cls, func) -> func |
|
|
|
""" |
|
|
|
generic_method.register(cls, func) -> func |
|
|
|
Registers a new implementation for the given *cls* on a *generic_method*. |
|
|
|
""" |
|
|
|
return self.dispatcher.register(cls, func=method) |
|
|
@ -47,3 +49,9 @@ __all__ = \ |
|
|
|
'cached_property', |
|
|
|
'singledispatchmethod', |
|
|
|
] |
|
|
|
|
|
|
|
__pdoc__ = \ |
|
|
|
{ |
|
|
|
'cached_property': False, |
|
|
|
'singledispatchmethod': False, |
|
|
|
} |