python@deprecated decorator不支持旧的python类、函数或方法。

Deprecated的Python项目详细描述


不推荐使用很容易使用

如果需要将函数或方法标记为已弃用, 您可以使用@deprecateddecorator:

保存在hello.py:

fromdeprecatedimportdeprecated@deprecated(version='1.2.1',reason="You should use another function")defsome_old_function(x,y):returnx+yclassSomeClass(object):@deprecated(version='1.3.0',reason="This method is deprecated")defsome_old_method(self,x,y):returnx+ysome_old_function(12,34)obj=SomeClass()obj.some_old_method(5,8)

而且易于设置

运行它:

$ pip install Deprecated
$ python hello.py
hello.py:15: DeprecationWarning: Call to deprecated function(or staticmethod) some_old_function.
(You should use another function) -- Deprecated since version 1.2.0.
  some_old_function(12, 34)
hello.py:17: DeprecationWarning: Call to deprecated method some_old_method.
(This method is deprecated) -- Deprecated since version 1.3.0.
  obj.some_old_method(5, 8)

您可以记录代码

您是否想过如何记录某些函数、类、方法等已弃用? 现在可以使用集成的sphinx指令执行此操作:

例如,在hello_sphinx.py:

fromdeprecated.sphinximportdeprecatedfromdeprecated.sphinximportversionaddedfromdeprecated.sphinximportversionchanged@versionadded(version='1.0',reason="This function is new")deffunction_one():'''This is the function one'''@versionchanged(version='1.0',reason="This function is modified")deffunction_two():'''This is the function two'''@deprecated(version='1.0',reason="This function will be removed soon")deffunction_three():'''This is the function three'''function_one()function_two()function_three()# warnshelp(function_one)help(function_two)help(function_three)

结果立即生效

运行:

$ python hello_sphinx.py

hello_sphinx.py:23: DeprecationWarning: Call to deprecated function(or staticmethod) function_three.
(This function will be removed soon) -- Deprecated since version 1.0.
  function_three()# warns

Help on function function_one in module __main__:

function_one()
    This is the function one

    .. versionadded:: 1.0
       This function is new

Help on function function_two in module __main__:

function_two()
    This is the function two

    .. versionchanged:: 1.0
       This function is modified

Help on function function_three in module __main__:

function_three()
    This is the function three

    .. deprecated:: 1.0
       This function will be removed soon

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java需要在没有数组的情况下获得最高值和最低值   java迭代JSON响应的结果Android+Reformation+Moshi   java透明JPanel   java Hibernate。getClass(对象代理)返回类,如何取而代之的是类<T>?   java Maven可以将模块部署到JBoss吗?   java如何在方向改变时处理服务   java将大量字符串加载到我的ArrayList中,我不想阻塞我的类   只使用Java流来映射是好的吗?   运行时的java编译时类型   java微小的图像,并没有旋转,但仍然会脱离内存错误:位图大小超过VM预算   java正在使用Intent启动新活动。安卓的NPE。所容纳之物ContextWrapper。getPackageName   用Java实现Comparator类   java Jtable requestFocusInWindow在第二次调用时失败   java如何导出包含excel文件和javafx的Maven项目?   使用POI的HSSFDataFormat定制java日期格式   java这两段代码之间的区别是什么?   运行简单swing程序时出现java错误