Craig
Craig

Reputation: 2366

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

Upvotes: 2

Views: 2086

Answers (1)

Laurent LAPORTE
Laurent LAPORTE

Reputation: 22942

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:

Upvotes: 2

Related Questions