Let's say I what to write a docstring for the code below:
def some_thing_cool(age, name):
better_age = age - 20
cooler_name = name + 'awesome'
bday_list = ['cake', 'balloons']
return bday_list
Would it be like this:
def some_thing_cool(age, name):
"""Something for bday
Args:
age (int) : age of bday person
name (string) : name of bday person
Variable:
better_age (int) : age - 20 for more pleasing age
cooler_name (string) : name + awesome
bday_list (list) : things to remember for bday
Returns:
bday_list (list) : best to return the list
"""
better_age = age - 20
cooler_name = name + 'awesome'
bday_list = ['cake', 'balloons']
return bday_list
Or should it be like this:
def some_thing_cool(age, name):
"""Something for bday
Args:
age (int) : age of bday person
name (string) : name of bday person
Returns:
bday_list (list) : best to return the list
"""
better_age = age - 20
cooler_name = name + 'awesome'
bday_list = ['cake', 'balloons']
return bday_list
And most importantly why should it be one way or another? (Do not think about the docstring style, this is not of importance in this question.) Most example I could find online does not include any variables when displaying how to write good docstrings, and this is constantly on my mind.
string, use the actual names you'd use in a type annotation, likestr. And, ideally,List[str]instead of justlist, because just knowing that it returns a list of something isn't all that helpful.ageis an age,nameis a name, andbday_listis "to return the list"… Maybe tell me thatbday_listis "decorations for birthday party" or something else I couldn't otherwise tell without reading the source code.