问题描述
在python中为类方法编写docstring时,在当前方法中包含可能由方法引发的异常是否是一个好习惯?即
import pandas as pd
class Foo:
def __init__(self):
pass
def bar(self,path):
"""
:param str path:
A filepath.
:returns:
The contents of the csv file specified by the "path" parameter.
:rtype:
pd.DataFrame
:raises
FileNotFoundError: If the file does not exist.
"""
return pd.read_csv(path)
在上面的示例中,Foo::bar() 方法永远不会显式引发“FileNotFoundError”异常,但它可能由 pandas.read_csv() 引发。在 bar() 的文档字符串的“raise”部分中包含异常是否是一个好习惯?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)