我试了一下效果和你不一样啊:
一样的代码,在 super(MyA, self).__init__() 这一行报错:
File "d:\Dev\python_projects\try_codegeex\ddeeff.py", line 11, in __init__
super(MyA, OrigA).__init__()
TypeError: super(type, obj): obj must be an instance or subtype of type
改了一下,似乎正常:
aabbcc.py================
class A(object):
def __init__(self):
print("in A.__init__")
class B(A):
def __init__(self):
print("in B.__init__")
A.__init__(self)
ddeeff.py================
import aabbcc
from aabbcc import A as OrigA
from aabbcc import B
class MyA(OrigA):
def __init__(self):
print("in MyA.__init__")
OrigA.__init__(self)
aabbcc.A = MyA
b = B()
输出==========
in B.__init__
in MyA.__init__
in A.__init__
【 在 CKevin 的大作中提到: 】
: 一开始的想法是能不能reload B,让B继承的实际上从OrigA变成MyA。然后发现不能rel
: oad指定的类只能reload模块整体。
: 后来想是不是把B也hotpatch一下,改一下其init方法。但是如果将来aabbcc.py库升级
: ...................
--
FROM 58.135.83.*