简体   繁体   English

如何使用 reST 文档字符串指定可调用参数的返回类型?

[英]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]不起作用

  • PyCharm 2021.2.4 x64 PyCharm 2021.2.4 x64
  • Python 3.9 Python 3.9

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.

相关问题 如何在单行ReST文档字符串中指定返回类型并描述返回值? - How to specify return type and describe the return value in one-line ReST docstring? django-rest-swagger:如何在文档字符串中指定参数类型 - django-rest-swagger: How can I specify the parameter type in the docstring 如何在Python文档字符串中定义“可调用”参数? - How to define a “callable” parameter in a Python docstring? 如何在python docstring中指定不同的返回类型 - How to specify different return types in python docstring 如何在 Python 的函数文档字符串中指定多个返回类型? - How to specify multiple return types in a function docstring in Python? Python:如何将Class function的参数类型指定为当前的ZA2F2ED4F8EBC2CBB4C21A9? - Python: How do you specify the parameter type of a Class function to the current class? 如何在 PyCharm 解析器的文档字符串中指定类或函数类型 - How to specify class or function type in docstring for PyCharm parser 如何为 Django model 指定构造函数文档字符串? - How do I specify the constructor docstring for a Django model? 如何检查 Callable 的返回类型 - How to inspect return type of Callable 如何指定使用pytest k参数运行的唯一测试? - How do you specify the only test to run with pytest k parameter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM