This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The `functools.singledispatchmethod` example in the document cannot run
Type: Stage: resolved
Components: Documentation Versions: Python 3.8
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, hongweipeng, jstasiak
Priority: normal Keywords: patch

Created on 2020-11-11 07:59 by hongweipeng, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23242 closed hongweipeng, 2020-11-12 02:39
Messages (3)
msg380741 - (view) Author: hongweipeng (hongweipeng) * Date: 2020-11-11 07:59
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.
msg380862 - (view) Author: Jakub Stasiak (jstasiak) * Date: 2020-11-12 23:17
There's an earlier issue created that relates to this (https://bugs.python.org/issue39679) and there are some possible solutions to get singledispatchmethod and classmethod work there.
msg380866 - (view) Author: hongweipeng (hongweipeng) * Date: 2020-11-13 02:01
Thanks,so close this one due to duplicate issue.
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86485
2020-11-13 02:01:48hongweipengsetstatus: open -> closed

messages: + msg380866
stage: patch review -> resolved
2020-11-12 23:17:30jstasiaksetnosy: + jstasiak
messages: + msg380862
2020-11-12 02:39:42hongweipengsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22139
2020-11-11 07:59:55hongweipengcreate