如何monkeypatch静态方法?

2024-05-29 07:09:01 发布

您现在位置:Python中文网/ 问答频道 /正文

虽然将monkeypatch实例方法转换为类非常简单,例如

class A(object):
    pass

def a(self):
    print "a"

A.a = a

使用另一个类的@staticmethodla来执行此操作

^{pr2}$

导致A.b()产生a

TypeError: unbound method b() must be called with A instance as first argument (got nothing instead)


Tags: 实例方法selfobjectdefpassmethodclass

热门问题