python@deprecated decorator不支持旧的python类、函数或方法。
Python-Deprecated的Python项目详细描述
python @deprecateddecorator来弃用旧的python类、函数或方法。
不推荐使用很容易使用
如果需要将函数或方法标记为已弃用, 您可以使用@deprecateddecorator:
保存在hello.py:
fromdeprecatedimportdeprecated@deprecateddefsome_old_function(x,y):returnx+yclassSomeClass(object):@deprecateddefsome_old_method(self,x,y):returnx+ysome_old_function(12,34)obj=SomeClass()obj.some_old_method(5,8)
而且易于设置
运行它:
$ pip install Python-Deprecated $ python hello.py hello.py:15: DeprecationWarning: Call to deprecated function some_old_function. some_old_function(12, 34) hello.py:17: DeprecationWarning: Call to deprecated function some_old_method. obj.some_old_method(5, 8)