mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
gh-127750: Improve repr of functools.singledispatchmethod (GH-130220)
This commit is contained in:
parent
67a942d427
commit
f33d21e24f
3 changed files with 85 additions and 0 deletions
|
@ -1033,6 +1033,15 @@ class singledispatchmethod:
|
|||
def __isabstractmethod__(self):
|
||||
return getattr(self.func, '__isabstractmethod__', False)
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
name = self.func.__qualname__
|
||||
except AttributeError:
|
||||
try:
|
||||
name = self.func.__name__
|
||||
except AttributeError:
|
||||
name = '?'
|
||||
return f'<single dispatch method descriptor {name}>'
|
||||
|
||||
class _singledispatchmethod_get:
|
||||
def __init__(self, unbound, obj, cls):
|
||||
|
@ -1052,6 +1061,19 @@ class _singledispatchmethod_get:
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
name = self.__qualname__
|
||||
except AttributeError:
|
||||
try:
|
||||
name = self.__name__
|
||||
except AttributeError:
|
||||
name = '?'
|
||||
if self._obj is not None:
|
||||
return f'<bound single dispatch method {name} of {self._obj!r}>'
|
||||
else:
|
||||
return f'<single dispatch method {name}>'
|
||||
|
||||
def __call__(self, /, *args, **kwargs):
|
||||
if not args:
|
||||
funcname = getattr(self._unbound.func, '__name__',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue