在文件B.py
中,我有一个函数hello()。该位置已弃用,我将其移动到A.py
目前我有:
def hello():
from A import hello as new_hello
warnings.warn(
"B.hello() is deprecated. Use A.hello() instead.",
DeprecationWarning
)
return new_hello()
但是调用函数时会发出警告。我想在导入函数时发出警告。如果像这样导入函数,是否可能发出警告:
from B import hello
B.py
还有一些其他函数,这些函数没有被弃用
在函数上使用decorator应该可以工作,在导入或调用函数时将显示警告。请仔细检查该函数在导入时是否未执行(不应该执行)
相关问题 更多 >
编程相关推荐