New submission from hongweipeng <hongweichen8...@sina.com>:
https://docs.python.org/zh-cn/3.8/library/functools.html#functools.singledispatchmethod as the code: ``` from functools import singledispatchmethod class Negator: @singledispatchmethod @classmethod def neg(cls, arg): raise NotImplementedError("Cannot negate a") @neg.register @classmethod def _(cls, arg: int): return -arg @neg.register @classmethod def _(cls, arg: bool): return not arg ``` File "/root/.pyenv/versions/3.8.5/lib/python3.8/functools.py", line 907, in register return self.dispatcher.register(cls, func=method) File "/root/.pyenv/versions/3.8.5/lib/python3.8/functools.py", line 849, in register raise TypeError( TypeError: Invalid first argument to `register()`: <classmethod object at 0x7fa22c0495b0>. Use either `@register(some_class)` or plain `@register` on an annotated function. ---------- assignee: docs@python components: Documentation messages: 380741 nosy: docs@python, hongweipeng priority: normal severity: normal status: open title: The `functools.singledispatchmethod` example in the document cannot run versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42319> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com