[英]How do you specify return type on a callable parameter with reST docstring?
Here's a working example with type hinting where I can annotate the parameter that it takes an int and a string and returns a boolean:这是一个带有类型提示的工作示例,我可以在其中注释它接受一个 int 和一个字符串并返回 boolean 的参数:
from typing import Callable
def func(another_func: Callable[[int, str], bool]):
pass
The relevant part is -> bool
in the picture above.相关部分是上图中的
-> bool
。 I'm trying to do the same thing with a reStructuredText docstring:我正在尝试使用 reStructuredText 文档字符串做同样的事情:
def func2(another_func):
""" :param function[int, str] another_func: """
This is the closest I've gotten in the picture above.这是我在上图中得到的最接近的。 Writing
function[[int, str], bool]
doesn't work编写
function[[int, str], bool]
不起作用
Change it to just like how PyCharm showed you how it looks like when using typing.Callable
:将其更改为就像 PyCharm 向您展示使用
typing.Callable
时的样子:
""" :param (int, str) -> bool another_func: """
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.