I would consider @return to be appropriate in this case because the function actually returns an iterator object with a next or send method. The validity of the statement x = my_generator(from=3) implies that my_generator really does return something. It merely does so without using the return statement to do it.

In some ways, functions containing a yield statement or expression behave like classes, because they are factories that return objects with predictable properties. However, because generator functions can themselves be declared and invoked as instance methods, I do not think of them as classes.

Answer from wberry on Stack Overflow
🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io › en › latest › example_google.html
Example Google Style Python Docstrings — napoleon 0.7 documentation
>>> print([i for i in example_generator(4)]) [0, 1, 2, 3] """ for i in range(n): yield i class ExampleError(Exception): """Exceptions are documented in the same way as classes. The __init__ method may be documented in either the class level docstring, or as a docstring on the __init__ method itself.
🌐
Readthedocs
numpydoc.readthedocs.io › en › latest › format.html
Style guide — numpydoc v1.11.1.dev1+gca74aae44 Manual
If a method has an equivalent function (which is the case for many ndarray methods for example), the function docstring should contain the detailed documentation, and the method docstring should refer to it. Only put brief summary and See Also sections in the method docstring. The method should use a Returns or Yields section, as appropriate.
🌐
Python-sprints
python-sprints.github.io › pandas › guide › pandas_docstring.html
pandas docstring guide — Python documentation
Parameters ---------- num1 : int First number to add num2 : int Second number to add Returns ------- int The sum of `num1` and `num2` See Also -------- subtract : Subtract one integer from another Examples -------- >>> add(2, 2) 4 >>> add(25, 0) 25 >>> add(10, -10) 0 """ return num1 + num2 ...
🌐
DataCamp
datacamp.com › tutorial › docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - In Python, you can access a docstring using the __doc__ attribute of the object. For example, you could access the docstring for a function using my_function.__doc__or the docstring for a class using MyClass.__doc__.
🌐
Python
peps.python.org › pep-0257
PEP 257 – Docstring Conventions | peps.python.org
There are two forms of docstrings: one-liners and multi-line docstrings. One-liners are for really obvious cases. They should really fit on one line. For example:
🌐
Readthedocs
pydoctor.readthedocs.io › en › latest › codedoc.html
How to Document Your Code — pydoctor documentation
To have the text \n in a docstring at runtime and in the generated documentation, you either have escape it twice in the source: \\n or use the r prefix for a raw string literal. The following example shows the raw string approach: def iter_lines(stream): r"""Iterate through the lines in the given text stream, with newline characters (\n) removed. """ for line in stream: yield line.rstrip('\n')
🌐
Google
google.github.io › styleguide › pyguide.html
Google Style Guides | Style guides for Google-originated open-source projects
It may also be omitted if the docstring starts with “Return”, “Returns”, “Yield”, or “Yields” (e.g. """Returns row from Bigtable as a tuple of strings.""") and the opening sentence is sufficient to describe the return value. Do not imitate older ‘NumPy style’ (example), which frequently documented a tuple return value as if it were multiple return values with individual names (never mentioning the tuple).
Find elsewhere
🌐
Lsst
developer.lsst.io › python › numpydoc.html
Documenting Python APIs with docstrings — LSST DM Developer Guide main documentation
The Parameters, Returns and Yields sections are the best places to describe specific input and output variables in detail. The Notes section can still reference these variables by name (see Marking up parameter names), and discuss how they work at a big-picture level. Most reStructuredText formatting is allowed in the Notes section, including: ... When using images, remember that many developers and users will be reading the docstring ...
🌐
JetBrains
jetbrains.com › help › pycharm › type-syntax-for-docstrings.html
Legacy type syntax for docstrings | PyCharm Documentation
March 18, 2026 - def my_iter(): for i in range(10): yield i for a in my_iter(): print a · Consider adding information about the expected parameter type. This information is specified using docstrings.
🌐
Programiz
programiz.com › python-programming › docstrings
Python Docstrings (With Examples)
For example, "I am a single-line comment" ''' I am a multi-line comment! ''' print("Hello World") Note: We use triple quotation marks for multi-line strings. ... As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in ...
🌐
Alvinntnu
alvinntnu.github.io › python-notes › python-basics › docstrings.html
Docstrings Format — Python Notes for Linguistics
>>> print([i for i in example_generator(4)]) [0, 1, 2, 3] """ for i in range(n): yield i class ExampleError(Exception): """Exceptions are documented in the same way as classes. The __init__ method may be documented in either the class level docstring, or as a docstring on the __init__ method itself.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Example 2: This function shows how to use triple double quotes for docstrings. ... def my_func(): """This is a docstring using triple double quotes.""" return None print(my_func.__doc__) ... This is a docstring using triple double quotes. Google style docstrings follow a specific format and are inspired by Google's documentation style guide. They provide a structured way to document Python code, including parameters, return values and descriptions.
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.6 documentation
Examples -------- >>> add(2, 2) 4 >>> add(25, 0) 25 >>> add(10, -10) 0 """ return num1 + num2 · Some standards regarding docstrings exist, which make them easier to read, and allow them be easily exported to other formats such as html or pdf. The first conventions every Python docstring should ...
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-30359 › PyCharm-doesnt-render-some-docstring-blocks-eg-Raises-and-Yields
PyCharm doesn't render some docstring blocks, e.g. Raises and Yields : PY-30359
>>> print([i for i in example_generator(4)]) [0, 1, 2, 3] """ for i in range(n): yield i ... Seems that random strings (e.g. Foo) do render, just not Yields (although Raises now works). As a workaround Yields_ works but it would be nice to have Yields. I'm on PyCharm 2021.2 (Professional Edition).
🌐
Zencoder
zencoder.ai › home › python docstring guide: format, examples & best practices
Python Docstring Guide: Format, Examples & Best Practices
December 3, 2025 - This guide dives deep into Python docstring, covering formats, examples, best practices, and how to leverage them to write clean, professional Python code.
🌐
Mkdocstrings
mkdocstrings.github.io › python › usage › configuration › docstrings
Docstrings - mkdocstrings-python
Whether to render the "Receives" section of docstrings. ... def iter_skip( iterable: Iterable[T], initial_skip: int = 0, ) -> Generator[T, int, None]: """Iterate and skip elements. Receives: skip: Number of elements to skip. """ skip = initial_skip for element in iterable: if skip or 0 > 0: skip -= 1 else: skip = yield element
🌐
DeepDocs
deepdocs.dev › home › 8 practical python docstring examples & patterns
8 Practical Python Docstring Examples & Patterns | DeepDocs
November 25, 2025 - This guide provides clear, actionable examples for the most common docstring formats you’ll encounter. We’ll break down Google Style, NumPy/SciPy, Sphinx, and others, offering a practical analysis of when and why to use each one. You’ll learn not just what these docstrings look like, but how they function in real-world scenarios. The Google Style docstring is a highly structured and readable format defined in the Google Python Style Guide.
🌐
GitHub
github.com › jsh9 › pydoclint
GitHub - jsh9/pydoclint: A very fast Python docstring linter · GitHub
Pydoclint is a Python docstring linter to check whether a docstring's sections (arguments, returns, raises, ...) match the function signature or function implementation.
Author: jsh9