Search code examples
pythonpydoc

How to document a parameter is a function type in python


def method(*, var_param, function_param):
    """Call 'function_param' with 'var_param'

    :param var_param: the value to pass to the function_param
    :type log: str
    :param function_param: the method to call with var_param
    :type function_param: ?????
    :return: Nothing
    :rtype: None
    """
    function_param(var_param)

I'm using pycharm 2017.1.1 to code and I was wondering what I need to put in the :type function_param: to indicate that a parameter is a 'function'?

== Edit ==

I tried using function, but pycharm complains:

screen shot from pycharm


Solution

  • You can use the "callable" type.

    def method(*, var_param, function_param):
        """Call 'function_param' with 'var_param'
    
        :param var_param: the value to pass to the function_param
        :type log: str
        :param function_param: the method to call with var_param
        :type function_param: callable[str]
        :return: Nothing
        :rtype: None
        """
        function_param(var_param)
    

    Since your parameter is a str, you can set this in the function signature.

    More info: