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 <[email protected]>
<http://bugs.python.org/issue27984>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com