Questions tagged [docstring]

A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.

A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.

For example, this Python module:

"""shibboleth.py - answer a common interview question with style and grace."""

DEFAULTS = (
    (3, "Fizz"),
    (5, "Buzz"),
)


def fizzbuzz(limit=15, sep=" ", **kwargs):
    """Print from 1 to `limit`, replacing as in the childhood game."""
    transform = sorted((v, k) for k, v in kwargs.items()) or DEFAULTS
    for number in range(1, limit + 1):
        matches = (word for factor, word in transform if number % factor == 0)
        print(sep.join(matches) or number)

... contains two docstrings: a module-level docstring which contains the filename of the module and a brief description of its purpose, and a function-level docstring which describes the behaviour of the function in which it occurs.

Conventions for writing Python docstrings can be found in PEP 257: Docstring Conventions.

Info on docstrings in other languages than Python can be found on Wikipedia.

745 questions
3
votes
1 answer

docstring that works with a Python class property?

I have a class defined below that has a class property called 'prop', and I want the docstring 'this is a property comment' to print out. The current behavior executes the getter for the property and prints 'getter'. Is there a way to setup the…
Michael Kelley
  • 3,579
  • 4
  • 37
  • 41
3
votes
1 answer

Error mkdocstrings generation error "No module named"

I was building a documentation site for my python project using mkdocstrings. For generating the code referece files I followed this instructions https://mkdocstrings.github.io/recipes/ I get these errors: INFO - Building…
egm2
  • 157
  • 1
  • 10
3
votes
1 answer

Proper way to document keys in TypedDict?

What is the proper way to document keys inside a TypedDict? I don't see much information inside PEP 589 – TypedDict. I can think of a few solutions: Document keys inside a docstring (is there a standard field to use here?): class Foo(TypedDict): …
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
3
votes
0 answers

how to find the docstring in the numpy.random module?

I try to find the docstring of the numpy.random.random() function in vscode. To do this i can keep navigating to the definition using go to definition from the menu or by pressing the f12 key. ...but i end up navigating to this line of code: …
D.L
  • 4,339
  • 5
  • 22
  • 45
3
votes
2 answers

python docstrings not working?

def myfunc(): """ My docstring """ print "hello" help(myfunc) I get 'more' is not recognized as an internal or external command, operable program or batch file. Windows 7 64bit, Python 2.6
jjrtf
  • 31
  • 1
  • 2
3
votes
3 answers

How to assign a type to a parameter in python?

I have a class named triangulo, and a class named coord. So, in a way to create a new instance of triangle, I pass three vertex like t= triangle( V1, V2, V3) So, for documentation, I want to write the class triangle in this way class triangulo(…
ArielCG
  • 33
  • 5
3
votes
2 answers

Can't generate Python docstring with autoDocstring extension in VS Code when multiline string in the function body

To generate documentation with Python Sphinx I have to use a specific docstring format. VS Code extension autoDocstring is capable to generate this specific format, but if the function contains multiline string then it doesn't work. Example in this…
Eqzt111
  • 487
  • 6
  • 17
3
votes
0 answers

Documenting a Side Effect in a Function Using reST Style Docstrings

I've been using reST style docstrings for a while, but I was browsing through the sphinx docs again to refresh my memory and realized that I'm not quite sure if there's a "standardized" way to document the side effects of a function. For instance,…
3
votes
1 answer

Sphinx meth role does not create a link

In a python module, in the docstring of the module I have the following: :meth:`my_method` and I have the following class in the current module: class GameP: ... def my_method(self): return f"{self._name} {self.selected}" Sphinx…
Green Falcon
  • 818
  • 3
  • 17
  • 48
3
votes
0 answers

docstrings in python stub files (*.pyi)

I have a python module used in production. This module is very old, that's why it doesn't have type annotations or docstrings. I can't modify this module. Using stub files (.pyi) I can write type annotations without any changes in the working files.…
shmakovpn
  • 751
  • 9
  • 10
3
votes
0 answers

How do put a bullet list in docstring for 'Raises'?

I couldn't figure out how to create a bullet list for Raises. See below. Is it even possible? What I got is a single bullet point for RuntimeError (same for ValueError). Like: Raises: • RuntimeError - ◦ case1: when x…
wood stock
  • 31
  • 2
3
votes
0 answers

Generate .pyi file which includes docstrings for .pyd binaries

I recently compiled opencv from source and am currently trying to get autocompletion and tooltips to work on vscode while using pylance language server. Unfortunately pylance does not support .pyd binary files. As a temporary solution i figured i…
3
votes
1 answer

Print a docstring of a program to stdout in Julia

Julia accepts ?sin on the command line to display a help text. I believe such help texts are implemented as docstrings. I would like to print such docstrings from my Julia program at runtime. How to do that?
3
votes
1 answer

VSCode auto complete string params for python

I've been looking around to see if I can create the same behaviour for Python in VSCode to show string param inputs as you can do with jsdoc in JavaScript. JavaScript example with JSDoc: /** * @method someMethod * @description A special method. *…
Steve
  • 4,372
  • 26
  • 37
3
votes
2 answers

Documenting class-level variables in Python

I am trying to document a Python class that has some class-level member variables, but I could not get it appropriately documented using reST/Sphinx. The code is this: class OSM: """Some blah and examples""" url =…