Message380741
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. |
|
Date |
User |
Action |
Args |
2020-11-11 07:59:55 | hongweipeng | set | recipients:
+ hongweipeng, docs@python |
2020-11-11 07:59:55 | hongweipeng | set | messageid: <1605081595.15.0.657429202369.issue42319@roundup.psfhosted.org> |
2020-11-11 07:59:55 | hongweipeng | link | issue42319 messages |
2020-11-11 07:59:54 | hongweipeng | create | |
|