处理自动抨击的库

deprecation的Python项目详细描述


折旧

Documentation Statushttps://travis-ci.org/briancurtin/deprecation.svg?branch=masterhttps://codecov.io/gh/briancurtin/deprecation/branch/master/graph/badge.svg

deprecation库提供了一个deprecated装饰器和 fail_if_not_removeddecorator用于您的测试。两个人在一起 实现以下几点的自动化:

  1. 已弃用方法的docstring获取弃用详细信息 附在它的末尾。如果直接生成api文档 从你的来源来看,你不需要担心自己的 通知。你也不必担心忘记 写下来。这是为你做的。
  2. 而不是因为你不赞成 但从来没有离开过,你可以做你的测试 告诉你什么时候该删除代码。那@deprecated 可以告诉decorator何时该完全删除代码, 这会导致@fail_if_not_removed引发AssertionError, 导致unittest或py.test测试失败。

有关完整文档,请参见http://deprecation.readthedocs.io/

安装

pip install deprecation

用法

import deprecation

@deprecation.deprecated(deprecated_in="1.0", removed_in="2.0",
                        current_version=__version__,
                        details="Use the bar function instead")
def foo():
    """Do some stuff"""
    return 1

…但是python不忽略DeprecationWarning

是的,从2.7开始就默认了,这是有充分理由的[1]-而且这工作得很好 带着这个。

  1. 使用-W标志或 PYTHONWARNINGS环境变量,以便捕捉警告 在开发中,并妥善处理。提出的警告 这个库出现在那里,因为它们是内置的子类 DeprecationWarning。见Command LineEnvironment Variable 有关更多详细信息的文档。
  2. 即使你不启用这些功能,这个库的行为 保持不变。docstring仍将被更新,测试 当他们需要的时候仍然会失败。不管怎样你都会得到好处的 python关心的是DeprecationWarning

[1]Exposing application users to ^{tt7}$s that are emitted by lower-level code needlessly involves end-users in “how things are done.” It often leads to users raising issues about warnings they’re presented, which on one hand is done rightfully so, as it’s been presented to them as some sort of issue to resolve. However, at the same time, the warning could be well known and planned for. From either side, loud ^{tt7}$s can be seen as noise that isn’t necessary outside of development.

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

推荐PyPI第三方库


热门话题
java在使用整数键遍历HashMap时,是否总是以升序返回键?   查找字符串中单词的长度,并查找有多少单词具有该长度。(爪哇)   java NoClassDefFoundError和其他引用Google Maps Android API实用程序时出现的错误   java Spring引导,在REST响应中将日期时间精度定义为毫秒   如何从json JAVA SPRING获取特定数据?   java删除特殊字符前后的空格   使用Java BigDecimal表示15精度的数字(比例为2)   java通过Cordova发布位置谷歌地图   java避免死锁的正确Hibernate会话超时值是多少?   带进度监视器的java JSch上载   java如何将SpringMVC、hibernate、hibernate验证器结合使用?   java SAXParser解析复杂对象   Java:将ArrayList<Byte>转换为Byte[]的最佳方法是什么?   java PostGIS jdbc sql查询   java如何动态设置Jtree节点图标   java重新设计MySQL表的主键