我在尝试使用 monkey patching 修改 pip 内部逻辑时,有些部分无法成功 patch。似乎与 pip._internal.operations.prepare.RequirementPreparer 有关。
我构造了一个类似的例子:
def fun1():
print("fun1")
def call_fun1():
fun1()
from a import fun1,call_fun1
def fun2():
print("fun2")
def patch():
import a
a.fun1=fun2
patch()
fun1()
call_fun1()
我希望的效果是两次均输出fun2,但实际上输出:
fun1
fun2
为什么其中一次会无法成功替换