简体   繁体   中英

Add dictionary keys in docstring sphinx

What is the recommended way of adding a docstring for the keys of a dictionary? I am using python 2.7 and Sphinx.

For instance, in the following code, how should I mention the keys 'a' and 'b' for my_dict? (But maybe it not necessary to go in such details):

def my_func(my_dict):
    """
    :param dict {'a': float, 'b': str} my_dict: description of param
    """
    pass

The implementation above seems to be not recognized by my Pycharm editor

EDIT: I also read this post , but the answer does not mention how to specify the 'names' of the keys

I usually go with the numpy style . Based on my personal experience, I believe it is a common docstring style used in the SciPy/NumPy/pandas Ecosystem. For the above function, you can write something like this.

def my_func(my_dict):
    """
    Parameters
    ----------
    my_dict : dict
        dict of {str: int}.
    """
    pass

See the pandas docstring guide for reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM