[Python] Defining docstring raises for functions not explicitly raising exception

Discussão em 'Python' iniciado por Stack, Agosto 16, 2025.

  1. Stack

    Stack Membro Participativo

    import requests

    def example():
    """An example function

    :raises KeyError: ?
    :raises HttpError: ?
    """
    result: Dict = do_something()
    log(result["key"])
    response = requests.get(url)
    return response


    The above function is not explicitly raising any exception, but as can be seen, its execution can potentially raise KeyError and HTTPError. Is it fine to mention these in docstring? What does the best practice say?

    Continue reading...

Compartilhe esta Página