Bug report
Bug description:
When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler, singledispatchmethod unconditionally attempts to call the __get__ method on that handler during dispatch.
This results in an AttributeError, because non-descriptor callables do not have a get method.
This behavior directly violates the explicit guarantee in singledispatchmethod's own docstring, which states that it does handle non-descriptor callables.
importfunctoolsclassMyCallable:
def__call__(self, host_self, arg):
returnf"Handled {arg} via MyCallable"classHost:
@functools.singledispatchmethoddefmy_method(self, arg):
returnf"Base handling for {arg}"callable_instance=MyCallable()
Host.my_method.register(int, callable_instance)
h=Host()
h.my_method(123)AttributeError: 'MyCallable'objecthasnoattribute'__get__'. Didyoumean: '__ge__'?
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
When a non-descriptor callable (such as a lambda or a class instance) is registered as a handler,
singledispatchmethodunconditionally attempts to call the__get__method on that handler during dispatch.This results in an AttributeError, because non-descriptor callables do not have a get method.
This behavior directly violates the explicit guarantee in
singledispatchmethod's own docstring, which states that it does handle non-descriptor callables.CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs