bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
(cherry picked from commit 445f1b35ce8461268438c8a6b327ddc764287e05)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
diff --git a/Lib/functools.py b/Lib/functools.py
index c8b79c2..24b011d 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -817,8 +817,13 @@
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