Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29403

Docstring parsing and formatting

From Ben Finney <ben+python@benfinney.id.au>
Subject Docstring parsing and formatting
Date 2012-09-18 12:03 +1000
Newsgroups comp.lang.python
Message-ID <mailman.853.1347933804.27098.python-list@python.org> (permalink)

Show all headers | View raw


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>).

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Docstring parsing and formatting Ben Finney <ben+python@benfinney.id.au> - 2012-09-18 12:03 +1000

csiph-web