I usually use the line style of a Google document , so the dictionary option will look like this:
def func(a_dict): """Some function to do something to a dictionary. Args: a_dict (dict of str: int): Some mapping, I guess? """ ...
A function that accepts **kwargs (note: this is not quite the same as having a dictionary parameter) would look like this:
def func(**kwargs): """Some function to do stuff to arbitrary keyword arguments. Args: **kwargs: Arbitrary keyword arguments. """ ...
If there are certain parameters that should be present (for example, your key1 ), they should be separate and not minimized to **kwargs .
In Python 3.x, you can also use function annotations :
def func(a_dict: dict): """Some function to do something to a dictionary.""" ...
Starting with Python 3.5, you can be even more understandable by typing :
from typing import Mapping def func(a_dict: Mapping[str, int]): """Some function to do something to a dictionary.""" ...
source share