How do you specify return type on a callable parameter with reST docstring?

Question:

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:

from typing import Callable

def func(another_func: Callable[[int, str], bool]):
    pass

Type hinting function

The relevant part is -> bool in the picture above. I’m trying to do the same thing with a reStructuredText docstring:

def func2(another_func):
    """ :param function[int, str] another_func: """

reSt example

This is the closest I’ve gotten in the picture above. Writing function[[int, str], bool] doesn’t work

  • PyCharm 2021.2.4 x64
  • Python 3.9
Asked By: Mandera

||

Answers:

Change it to just like how PyCharm showed you how it looks like when using typing.Callable:

""" :param (int, str) -> bool another_func: """
Answered By: Matiiss