diff -r 9fb30d6af6a9 Lib/functools.py --- a/Lib/functools.py Tue Sep 06 21:12:44 2016 -0700 +++ b/Lib/functools.py Wed Sep 07 17:38:20 2016 +0800 @@ -709,6 +709,8 @@ """ nonlocal cache_token + if not isinstance(cls, type): + raise TypeError("dispatch() argument must be a type") if cache_token is not None: current_token = get_cache_token() if cache_token != current_token: @@ -731,6 +733,8 @@ """ nonlocal cache_token + if not isinstance(cls, type): + raise TypeError("register() argument must be a type") if func is None: return lambda f: register(cls, f) registry[cls] = func diff -r 9fb30d6af6a9 Lib/test/test_functools.py --- a/Lib/test/test_functools.py Tue Sep 06 21:12:44 2016 -0700 +++ b/Lib/test/test_functools.py Wed Sep 07 17:38:20 2016 +0800 @@ -1465,6 +1465,18 @@ class TestSingleDispatch(unittest.TestCase): + def test_arguments_type(self): + # issue27984 + from enum import Enum + IS = Enum("IS", "a, b") + @functools.singledispatch + def g(obj): + return "base" + with self.assertRaisesRegex(TypeError, "argument must be a type"): + g.register(IS.a) + with self.assertRaisesRegex(TypeError, "argument must be a type"): + g.dispatch(IS.b) + def test_simple_overloads(self): @functools.singledispatch def g(obj):