gh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (GH-140884)

This commit is contained in:
Serhiy Storchaka 2025-11-13 19:48:52 +02:00 committed by GitHub
parent b99db92dde
commit b2b68d40f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 52 additions and 3 deletions

View file

@ -1083,7 +1083,10 @@ def __call__(self, /, *args, **kwargs):
'singledispatchmethod method')
raise TypeError(f'{funcname} requires at least '
'1 positional argument')
return self._dispatch(args[0].__class__).__get__(self._obj, self._cls)(*args, **kwargs)
method = self._dispatch(args[0].__class__)
if hasattr(method, "__get__"):
method = method.__get__(self._obj, self._cls)
return method(*args, **kwargs)
def __getattr__(self, name):
# Resolve these attributes lazily to speed up creation of