Python 3.5 Iterator[] annotation

They offer a standardized Iterator[] syntax for this as documented at: https://docs.python.org/3/library/typing.html#typing.Generator

Before Python 3, I recommend that you use this syntax to make it easier to port later on:

def f():
    """
    :rtype: Iterator[:class:`SomeClass`]
    """
    yield SomeClass()

And after Python 3, use https://pypi.python.org/pypi/sphinx-autodoc-annotation with syntax:

from typing import Iterator
def f() -> Iterator[SomeClass]:
    yield SomeClass()
Answer from Ciro Santilli OurBigBook.com on Stack Overflow
🌐
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
For axis, the convention is to use something like: axis : {0 or ‘index’, 1 or ‘columns’, None}, default None · If the method returns a value, it will be documented in this section. Also if the method yields its output.
🌐
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. You can use different docstrings depending on the selected docstring format, for example, :type, @type, or Args. Use project settings to alter the docstring format (Settings | Python | Tools | Integrated Tools) .
🌐
GitHub
github.com › terrencepreilly › darglint › issues › 165
False-positive DAR301 for yielding function/method when using Sphinx-style docstrings · Issue #165 · terrencepreilly/darglint
April 16, 2021 - When a function/method uses yield, Darglint outputs an error as follows: DAR301: foo_function: Missing "Yields" in Docstring: - yield Though this is correct for e.g. Google-style docstrin...
Author: terrencepreilly
🌐
Google
google.github.io › styleguide › pyguide.html
Google Style Guides | Style guides for Google-originated open-source projects
Fine. Use “Yields:” rather than “Returns:” in the docstring for generator functions.
🌐
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.
🌐
GitHub
github.com › sphinx-doc › sphinx › issues › 10134
Inconsistent rendering of return/yield value documentation in NumPy-style docstrings · Issue #10134 · sphinx-doc/sphinx
January 26, 2022 - Returns ------- return1 : int Description of ``return1``. """ return 42 def test_two_returns_type_in_docstring(): """Test function with two return values. Returns ------- return1 : int Description of ``return1``. return2 : float Description of ``return2``. """ return 42, 42.0 · The documentation of the function test_one_yield should render exactly like the documentation test_one_yield_type_in_docstring.
Author: sphinx-doc
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
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. ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Astral
docs.astral.sh › ruff › rules › docstring-extraneous-yields
docstring-extraneous-yields (DOC403) | Ruff - Astral Docs
def say_hello(n: int) -> None: """Says hello to the user. Args: n: Number of times to say hello. Yields: Doesn't yield anything. """ for _ in range(n): print("Hello!") ... def say_hello(n: int) -> None: """Says hello to the user. Args: n: Number of times to say hello. """ for _ in range(n): print("Hello!")
Starred by 32 users
Forked by 2 users
Languages: TypeScript 93.5% | JavaScript 6.5% | TypeScript 93.5% | JavaScript 6.5%
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.6 documentation
For axis, the convention is to use something like: axis : {0 or ‘index’, 1 or ‘columns’, None}, default None · If the method returns a value, it will be documented in this section. Also if the method yields its output.
🌐
Python.org
discuss.python.org › python help
Function Docstring Generator - Python Help - Discussions on Python.org
April 12, 2021 - Hey all, there are many tools/packages aimed towards building documentation from code, however I was wondering if someone could point me in the direction of a module designed to automatically generate function docstrings? So something along the lines of def my_func(n: int) -> int: return n*n (now running the module from the commandline) def my_func(n: int) -> int: """[summary placeholder] Args: param1 (int) : [param1 placeholder] Returns: int: [Return value...
🌐
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. It runs really fast.
Author: jsh9
🌐
GitHub
github.com › mkdocstrings › pytkdocs › issues › 89
Support 'Yields' in Google-style docstrings · Issue #89 · mkdocstrings/pytkdocs
January 19, 2021 - I had a docstring of a generator that I was using mkdocstrings (v0.14.0) to compile the documentation for, something like: """ Get the next number in the sequence Args: n (int): The upper limit of the range to generate, from 0 to `n` - 1. Yields: int: The next number in the range of 0 to `n` - 1.
Author: mkdocstrings
🌐
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')
🌐
Noirlab
datalab.noirlab.edu › docs › manual › DevGuide › DocumentingPythonAPIswithDocstrings › DocumentingPythonAPIswithDocstrings.html
3.2. Documenting Python APIs with Docstrings — Data Lab documentation
We organize Python docstrings into sections that appear in a common order. This format follows the Numpydoc standard (used by NumPy, SciPy, and Astropy, among other scientific Python packages) rather than the format described in PEP 287. These are the sections and their relative order: Short Summary · Deprecation Warning (if applicable) Extended Summary (optional) Parameters (if applicable; for classes, methods, and functions) Returns or Yields (if applicable; for functions, methods, and generators) Other Parameters (if applicable; for classes, methods, and functions) Raises (if applicable) See Also (optional) Notes (optional) References (optional) Examples (optional) For summaries of how these docstring sections are composed in specific contexts, see: Documenting Modules ·
🌐
DataCamp
datacamp.com › tutorial › docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - Python documentation string, commonly known as docstring, is a string literal, and it is used in the class, module, function, or method definition. Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function.