开发者

How can I tell if a given method is a classmethod or instancemethod in Python?

开发者 https://www.devze.com 2022-12-11 05:17 出处:网络
Checking to see if m.im_self is the class works some of the time but doesn\'t seem开发者_Go百科 to be 100% reliable (ex. if you use multiple decorators on a method.)If it\'s a bound method on the clas

Checking to see if m.im_self is the class works some of the time but doesn't seem开发者_Go百科 to be 100% reliable (ex. if you use multiple decorators on a method.)


If it's a bound method on the class then it's a classmethod.

from inspect import ismethod, isclass
def isclassmethod( m ):
 return ismethod(m) and isclass(m.__self__)
0

精彩评论

暂无评论...
验证码 换一张
取 消