Python zope.deprecation
This package provides a simple function called deprecated(names, reason)
to mark deprecated modules, classes, functions, methods and properties. readthedocs
Usage
function
对函数进行弃用说明, readthedocs 使用将例子直接放到 zope.deprecation
package 路径的操作, tmp_d = tempfile.mkdtemp('deprecation'); zope.deprecation.__path__.append(tmp_d)
这里的例子没有这样做.
# cat deprecate demo.py
from zope.deprecation import deprecated
# in function
def demo1():
return 1
deprecated('demo1', 'demo1 is no more.')
def demo4():
return 4
def deprecatedemo4():
"""Demonstrate that deprecated() also works in a local scope."""
deprecated('demo4', 'demo4 is no more.')
测试 deprecated 是否可用
>>> import warnings
>>> import demo
>>> with warnings.catch_warnings(record=True) as log:
... del warnings.filters[:]
... doctest_ex.demo1()
1
>>> print log[0].category.__name__
DeprecationWarning
>>> print log[0].message
demo1: demo1 is no more.
>>> import demo
>>> with warnings.catch_warnings(record=True) as log:
... del warnings.filters[:]
... zope.deprecation.doctest_ex.demo2()
2
>>> print log[0].message
demo2: demo2 is no more.
properties and function in class
from zope.deprecation import deprecation
class MyComponent(object):
foo = property(lambda self: 1)
# properties
foo = deprecation.deprecated(foo, 'foo is no more.')
bar = 2
def blah(self):
return 3
blah = deprecation.deprecated(blah, 'blah() is no more.')
def splat(self):
return 4
@deprecation.deprecate("clap() is no more.")
def clap(self):
return 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: Python doctest
下一篇: Covenant 利用分析
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论