Python Google-Style DocString for Function with No Arguments
Asked Answered
K

1

5

I've been using the Google-Style Python Docstring format for a while now. The way I've been handling functions/methods with no arguments suddenly doesn't look correct to me. I did a bit of searching and couldn't find anything online that specified how to handle that situation.

When there is no return, I've seen None used and I'm okay with that because that is technically what gets returned. However, using None for the args can imply that there's actually a single argument that's expected to be of the type: NoneType.

Currently, what I've been doing looks something like this:

def foo():
    """
    blah blah blah

    Args:
        None
    Returns:
        The number 5
    """
    return 5

My question is, which format should I use instead (I prefer to always have an Args section)? Or perhaps my current approach isn't really that bad and is common practice.

Some other candidates (feel free to provide your own if you feel there's a better format):

def foo():
    """
    blah blah blah

    Args:

    Returns:
        The number 5
    """
    return 5
def foo():
    """
    blah blah blah

    Args:
        No arguments
    Returns:
        The number 5
    """
    return 5
def foo():
    """
    blah blah blah

    Returns:
        The number 5
    """
    return 5
Kine answered 21/3, 2020 at 22:3 Comment(0)
A
6

It looks to me like the standard is to not have an 'Arguments' section if there are no arguments to the function. The same style as the final candidate you listed.

This is not explicitly mentioned, but I inferred this from the examples at:

Affecting answered 3/9, 2020 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.