chi*_*ffa 6 python eclipse pydev
我正在使用Eclipse和Pydev编辑我的Python源代码.
我想记录我的所有函数,并在函数尚未实现时引发"未实现"异常.
例如,当我键入:
def foo(bar1,bar2):
Run Code Online (Sandbox Code Playgroud)
在输入时,我希望它能自动完成:
def foo(bar1,bar2):
'''
function foo
@param bar1:
@type:
@param bar2:
@type
'''
raise NotImplementedError("")
Run Code Online (Sandbox Code Playgroud)
Pydev或Eclipse中是否已经有一个选项可以做到这一点?如果没有,是否有一个单独的Python模块或脚本可以正确地执行它?
目前,文档已经生成.
即:在'def'行中,按Ctrl + 1将显示选项"Generated Docstring"(这些docstring的格式可以在 首选项> pydev>编辑器>代码样式> docstrings中定义).
至于raise NotImplementedError(""),目前无法自动添加.
就个人而言,我使用的是一个'抽象'装饰器,例如:
def abstract(func):
def wrapper(self, *args, **kwargs):
msg = 'Method %r not implemented in class %r.' % (func.__name__, self.__class__)
raise NotImplementedError(msg)
wrapper.__name__ = func.__name__
wrapper.__doc__ = func.__doc__
return wrapper
Run Code Online (Sandbox Code Playgroud)
然后使用:
@abstract
def my_func(xxx, yyy):
...
Run Code Online (Sandbox Code Playgroud)
这样,如果有人调用你的代码,消息看起来更好:)
| 归档时间: |
|
| 查看次数: |
3679 次 |
| 最近记录: |