Docstring parsing and formatting

Ben Finney ben+python at benfinney.id.au
Mon Sep 17 22:03:09 EDT 2012


Howdy all,

Where can I find a standard implementation of the docstring parsing and
splitting algorithm from PEP 257?


PEP 257 describes a convention of structure and formatting for
docstrings <URL: http://www.python.org/dev/peps/pep-0257/>. Docstrings
that conform to this convention can therefore be parsed into their
component parts, and re-formatted.

The PEP describes <URL: http://www.python.org/dev/peps/pep-0257/#id20>
and algorithm for parsing the docstring as found in the string literal.
It says “Docstring processing tools will …” and goes on to describe, in
prose and example code, how the parsing should be done.

Where is a common implementation of that algorithm? It seems that it
should be in the Python standard library, but I can't find it.

Ideally what I want is to be able to write:

    import textwrap

    (summary, description) = textwrap.pep257_parse(foo.__doc__)

and have ‘summary’ as the docstring's summary line, and ‘description’ as
the docstring's description (as described in <URL:
http://www.python.org/dev/peps/pep-0257/#id19>).




More information about the Python-list mailing list