[issue27984] singledispatch register should typecheck its argument
Xiang Zhang
report at bugs.python.org
Wed Sep 7 05:39:08 EDT 2016
Xiang Zhang added the comment:
It's also better to add the typecheck to dispatch. Otherwise sometimes it can generate not obvious exception message.
>>> from enum import IntEnum
>>> from functools import singledispatch
>>> IS = IntEnum("IS", "a, b")
>>> @singledispatch
... def foo(x):
... pass
...
>>> foo.dispatch(IS.a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/angwer/cpython/Lib/functools.py", line 718, in dispatch
impl = dispatch_cache[cls]
File "/home/angwer/cpython/Lib/weakref.py", line 365, in __getitem__
return self.data[ref(key)]
TypeError: cannot create weak reference to 'IS' object
>>>
----------
keywords: +patch
nosy: +xiang.zhang
Added file: http://bugs.python.org/file44428/issue27984.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27984>
_______________________________________
More information about the Python-bugs-list
mailing list