[New-bugs-announce] [issue42319] The `functools.singledispatchmethod` example in the document cannot run

hongweipeng report at bugs.python.org
Wed Nov 11 02:59:55 EST 2020


New submission from hongweipeng <hongweichen8888 at 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 at python
components: Documentation
messages: 380741
nosy: docs at python, hongweipeng
priority: normal
severity: normal
status: open
title: The `functools.singledispatchmethod` example in the document cannot run
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42319>
_______________________________________


More information about the New-bugs-announce mailing list