gh-85294: Handle missing arguments to @singledispatchmethod gracefully (GH-21471)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Ammar Askar 2024-02-16 16:17:30 -05:00 committed by GitHub
parent 5903190727
commit 8b776e0f41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 2 deletions

View file

@ -918,7 +918,6 @@ def singledispatch(func):
if not args:
raise TypeError(f'{funcname} requires at least '
'1 positional argument')
return dispatch(args[0].__class__)(*args, **kw)
funcname = getattr(func, '__name__', 'singledispatch function')
@ -968,7 +967,11 @@ class singledispatchmethod:
return _method
dispatch = self.dispatcher.dispatch
funcname = getattr(self.func, '__name__', 'singledispatchmethod method')
def _method(*args, **kwargs):
if not args:
raise TypeError(f'{funcname} requires at least '
'1 positional argument')
return dispatch(args[0].__class__).__get__(obj, cls)(*args, **kwargs)
_method.__isabstractmethod__ = self.__isabstractmethod__