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
))
self.assertTrue(str(exc.exception).endswith(msg_suffix))
+ def test_invalid_positional_argument(self):
+ @functools.singledispatch
+ def f(*args):
+ pass
+ msg = 'f requires at least 1 positional argument'
+ with self.assertRaisesRegexp(TypeError, msg):
+ f()
if __name__ == '__main__':
unittest.main()