docstring

Defining docstring raises for functions not explicitly raising exception

Defining docstring raises for functions not explicitly raising exception Question: 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 …

Total answers: 2

Copying the docstring of function onto another function by name

Copying the docstring of function onto another function by name Question: I’m looking to copy the docstring of a function in the same file by name (with a decorator). I can easily do it with a function that is out of the current module, but I’m a bit confused when it comes to the same …

Total answers: 2

How do you fix "Missing module docstringpylint(missing-module-docstring)"

How do you fix "Missing module docstringpylint(missing-module-docstring)" Question: I’m using the pygame module on VS Code and I ran into the issue where the pygame has not init member. I followed the solutions to this link. I edited the user settings and added "python.linting.pylintArgs": [ "–extension-pkg-whitelist=pygame", "–unsafe-load-any-extension=y" ] to the end of the json file …

Total answers: 4

Why is imperative mood important for docstrings?

Why is imperative mood important for docstrings? Question: The error code D401 for pydocstyle reads: First line should be in imperative mood. I often run into cases where I write a docstring, have this error thrown by my linter, and rewrite it — but the two docstrings are semantically identical. Why is it important to …

Total answers: 7

Python Visual Studio Code autoDocstring Configuration

Python Visual Studio Code autoDocstring Configuration Question: Goal: generate docstring in vscode for Python automatically and format the generated docstring to my liking. Solution: I installed the autoDocstring extension. Problem: I don’t know how to get the generated docstring to be formatted the way I want it. In the description under the “Extension Settings” heading, …

Total answers: 2

How do I document a constructor for a class using Python dataclasses?

How do I document a constructor for a class using Python dataclasses? Question: I have some existing Python 3.6 code that I’d like to move to Python 3.7 dataclasses. I have __init__ methods with nice docstring documentation, specifying the attributes the constructors take and their types. However, if I change these classes to use the …

Total answers: 3

Python 3.6.1: How to dynamically print a docstring?

Python 3.6.1: How to dynamically print a docstring? Question: While reading some Python training books, I was tinkering a little bit with objects, like printing docstrings for common objects and attributes. Consider the list of strings returned by: dir(str) I am trying to iterate over the above in order to dynamically print the docstrings of …

Total answers: 2

How to specify different return types in python docstring

How to specify different return types in python docstring Question: I’m currently writing documentation for my python package using Sphinx and the autodoc plugin. For a function return value I can e.g. write :returns: int: count which tells sphinx that there is a return value of type int, named count. I now got a function …

Total answers: 2

Python docstrings to GitHub README.md

Python docstrings to GitHub README.md Question: How do I transcode Python documentation strings to a GitHub readme.md file? Even though it seems like something everyone does, I cannot seem to get a decent solution and I am assuming it should be easy, so it seems unlikely folks are going throw two converters… What I have …

Total answers: 5

Python Docstring: raise vs. raises

Python Docstring: raise vs. raises Question: I use the PyCharm IDE which assists with crafting PEP0257-compliant docstrings. It provides two attributes I don’t entirely understand the distinction/use between: :raise Exception: exception explanation here :raises Exception: exception explanation here When would I use raise as opposes to raises in my docstring? Specifically, if a class required …

Total answers: 4