源代码如下:
class classonlymethod(classmethod):
def __get__(self, instance, owner):
if instance is not None:
raise AttributeError("This method is available only on the view class.")
return super(classonlymethod, self).__get__(instance, owner)
Run Code Online (Sandbox Code Playgroud)
虽然我可以看到 classonlymethod 只能在类上调用,而不能在实例上调用,这与 python 的 classmethod 不同,为什么我们需要这样的“限制”?
www 上关于 classonlymethod 的内容不多,并且一如既往地赞赏任何外行示例。
| 归档时间: |
|
| 查看次数: |
1368 次 |
| 最近记录: |