python - mypy 可以检查文档字符串吗?
问题描述
def foobar(filename, copy, dtype, iterable, shape, files):
"""
foobar is 42.
Parameters
----------
filename : str
copy : bool
dtype : data-type
iterable : iterable object
shape : int or tuple of int
files : list of str
Returns
-------
foobarfoo : int
"""
pass
是否可以检查文档字符串类型是否正确?
(附带问题:numpy 可以返回/打印它发现的函数签名吗?)
例如,我希望以下失败:
返回类型
def foobar():
"""
Returns
-------
blub : int
"""
return "foo"
或者
def foobar(a, b):
"""
Parameters
----------
a : number
b : number
Returns
-------
blub : int
"""
if a > b:
return "foo"
return 42
参数类型
def foobar(a, b):
"""
Parameters
----------
a : str
b : int
Returns
-------
blub : int
"""
return a * b
解决方案
不,mypy 只理解官方 Python 的打字符号。请参阅mypy 文档。这很好,我们不需要很多替代方法来输入注释,因为
应该有一种——最好只有一种——明显的方法来做到这一点。
推荐阅读
- javascript - 直方图类型 highcharts 访问系列
- ansible - 更改当前目录并留在那里
- python - 打开图像并关闭它,外部程序
- python - 如何键入提示函数的可选返回参数?
- reactjs - 导航栏崩溃不适用于 React-Bootstrap
- javascript - 如何从此代码自定义移动和桌面显示的警报框?
- java - Java JFrame 不会更新输入的文本
- python - Python3 在 Linux 中调用 Python2 多处理的行为与在 Windows 中不同
- javascript - 自定义重试功能
- c - 遵循 C 代码为什么正确使用 graph->array[i].head 和 graph->array[i]->head 给出错误?