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以适当的方式更新jLabel和jTextField   java如何从PQ(单链表)中删除最大值   java可以通过任何方式找出哪些NSF文件属于Domino服务器   java Velocity 2不会设置属性   如何使用java流迭代索引映射列表   maven依赖项在编译期间工作,但在java运行时失败。lang.NoClassDefFoundError&java。lang.ClassNotFoundException   java有没有办法完全隐藏Web应用程序代码?   Android appcompat v7 21库中的java FadingActionBar错误   Eclipse/com中的java AdMob。谷歌。安卓gms。ads.AdView   java My Service表示它正在运行,但其状态尚不清楚,似乎没有绑定   java无法启动Apache Tomcat Web应用程序容器   JDK:java中的命名约定。可丢弃的   Spring SerSecurity中的java身份验证错误   Maven:使用JDK8编译Java7   java在使用ExecutorService时如何管理内存?   comm.jar通信串行端口java   java LibGDX创建动画