bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)

This commit is contained in:
Dong-hee Na 2018-07-10 16:26:36 +09:00 committed by INADA Naoki
parent 7762e4d387
commit 445f1b35ce
3 changed files with 14 additions and 0 deletions

View file

@ -817,8 +817,13 @@ def singledispatch(func):
return func
def wrapper(*args, **kw):
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')
registry[object] = func
wrapper.register = register
wrapper.dispatch = dispatch