Movatterモバイル変換


[0]ホーム

URL:


Following system colour schemeSelected dark colour schemeSelected light colour scheme

Python Enhancement Proposals

PEP 256 – Docstring Processing System Framework

PEP 256 – Docstring Processing System Framework

Author:
David Goodger <goodger at python.org>
Discussions-To:
Doc-SIG list
Status:
Rejected
Type:
Standards Track
Created:
01-Jun-2001
Post-History:
13-Jun-2001

Table of Contents

Rejection Notice

This proposal seems to have run out of steam.

Abstract

Python lends itself to inline documentation. With its built-indocstring syntax, a limited form ofLiterate Programming is easy todo in Python. However, there are no satisfactory standard tools forextracting and processing Python docstrings. The lack of a standardtoolset is a significant gap in Python’s infrastructure; this PEP aimsto fill the gap.

The issues surrounding docstring processing have been contentious anddifficult to resolve. This PEP proposes a generic DocstringProcessing System (DPS) framework, which separates out the components(program and conceptual), enabling the resolution of individual issueseither through consensus (one solution) or through divergence (many).It promotes standard interfaces which will allow a variety of plug-incomponents (input context readers, markup parsers, and output formatwriters) to be used.

The concepts of a DPS framework are presented independently ofimplementation details.

Road Map to the Docstring PEPs

There are many aspects to docstring processing. The “Docstring PEPs”have broken up the issues in order to deal with each of them inisolation, or as close as possible. The individual aspects andassociated PEPs are as follows:

  • Docstring syntax.PEP 287, “reStructuredText Docstring Format”,proposes a syntax for Python docstrings, PEPs, andother uses.
  • Docstring semantics consist of at least two aspects:
    • Conventions: the high-level structure of docstrings. Dealt withinPEP 257, “Docstring Conventions”.
    • Methodology: rules for the informational content of docstrings.Not addressed.
  • Processing mechanisms. This PEP (PEP 256) outlines the high-levelissues and specification of an abstract docstring processing system(DPS).PEP 258, “Docutils Design Specification”, is anoverview of the design and implementation of one DPS underdevelopment.
  • Output styles: developers want the documentation generated fromtheir source code to look good, and there are many different ideasabout what that means.PEP 258 touches on “Stylist Transforms”.This aspect of docstring processing has yet to be fully explored.

By separating out the issues, we can form consensus more easily(smaller fights ;-), and accept divergence more readily.

Rationale

There are standard inline documentation systems for some otherlanguages. For example, Perl hasPOD (“Plain Old Documentation”) andJava hasJavadoc, but neither of these mesh with the Pythonic way.POD syntax is very explicit, but takes after Perl in terms ofreadability. Javadoc is HTML-centric; except for “@field” tags,raw HTML is used for markup. There are also general tools such asAutoduck andWeb (Tangle & Weave), useful for multiple languages.

There have been many attempts to write auto-documentation systemsfor Python (not an exhaustive list):

  • Marc-Andre Lemburg’sdoc.py
  • Daniel Larsson’spythondoc &gendoc
  • Doug Hellmann’sHappyDoc
  • Laurence Tratt’s Crystal (no longer available on the web)
  • Ka-Ping Yee’spydoc (pydoc.py is now part of the Python standardlibrary; see below)
  • Tony Ibbs’docutils (Tony has donated this name to theDocutilsproject)
  • Edward Loper’sSTminus formalization and related efforts

These systems, each with different goals, have had varying degrees ofsuccess. A problem with many of the above systems was over-ambitioncombined with inflexibility. They provided a self-contained set ofcomponents: a docstring extraction system, a markup parser, aninternal processing system and one or more output format writers witha fixed style. Inevitably, one or more aspects of each system hadserious shortcomings, and they were not easily extended or modified,preventing them from being adopted as standard tools.

It has become clear (to this author, at least) that the “all ornothing” approach cannot succeed, since no monolithic self-containedsystem could possibly be agreed upon by all interested parties. Amodular component approach designed for extension, where componentsmay be multiply implemented, may be the only chance for success.Standard inter-component APIs will make the DPS componentscomprehensible without requiring detailed knowledge of the whole,lowering the barrier for contributions, and ultimately resulting in arich and varied system.

Each of the components of a docstring processing system should bedeveloped independently. A “best of breed” system should be chosen,either merged from existing systems, and/or developed anew. Thissystem should be included in Python’s standard library.

PyDoc & Other Existing Systems

PyDoc became part of the Python standard library as of release 2.1.It extracts and displays docstrings from within the Python interactiveinterpreter, from the shell command line, and from a GUI window into aweb browser (HTML). Although a very useful tool, PyDoc has severaldeficiencies, including:

  • In the case of the GUI/HTML, except for some heuristic hyperlinkingof identifier names, no formatting of the docstrings is done. Theyare presented within<p><small><tt> tags to avoid unwanted linewrapping. Unfortunately, the result is not attractive.
  • PyDoc extracts docstrings and structural information (classidentifiers, method signatures, etc.) from imported module objects.There are security issues involved with importing untrusted code.Also, information from the source is lost when importing, such ascomments, “additional docstrings” (string literals in non-docstringcontexts; seePEP 258), and the order of definitions.

The functionality proposed in this PEP could be added to or used byPyDoc when serving HTML pages. The proposed docstring processingsystem’s functionality is much more than PyDoc needs in its currentform. Either an independent tool will be developed (which PyDoc mayor may not use), or PyDoc could be expanded to encompass thisfunctionality andbecome the docstring processing system (or onesuch system). That decision is beyond the scope of this PEP.

Similarly for other existing docstring processing systems, theirauthors may or may not choose compatibility with this framework.However, if this framework is accepted and adopted as the Pythonstandard, compatibility will become an important consideration inthese systems’ future.

Specification

The docstring processing system framework is broken up as follows:

  1. Docstring conventions. Documents issues such as:
    • What should be documented where.
    • First line is a one-line synopsis.

    PEP 257 documents some of these issues.

  2. Docstring processing system design specification. Documentsissues such as:
    • High-level spec: what a DPS does.
    • Command-line interface for executable script.
    • System Python API.
    • Docstring extraction rules.
    • Readers, which encapsulate the input context.
    • Parsers.
    • Document tree: the intermediate internal data structure. Theoutput of the Parser and Reader, and the input to the Writer allshare the same data structure.
    • Transforms, which modify the document tree.
    • Writers for output formats.
    • Distributors, which handle output management (one file, manyfiles, or objects in memory).

    These issues are applicable to any docstring processing systemimplementation.PEP 258 documents these issues.

  3. Docstring processing system implementation.
  4. Input markup specifications: docstring syntax.PEP 287proposes a standard syntax.
  5. Input parser implementations.
  6. Input context readers (“modes”: Python source code, PEP, standalonetext file, email, etc.) and implementations.
  7. Stylists: certain input context readers may have associatedstylists which allow for a variety of output document styles.
  8. Output formats (HTML, XML, TeX, DocBook, info, etc.) and writerimplementations.

Components 1, 2/3/5, and 4 are the subject of individual companionPEPs. If there is another implementation of the framework orsyntax/parser, additional PEPs may be required. Multipleimplementations of each of components 6 and 7 will be required; thePEP mechanism may be overkill for these components.

Project Web Site

A SourceForge project has been set up for this work athttp://docutils.sourceforge.net/.

Copyright

This document has been placed in the public domain.

Acknowledgements

This document borrows ideas from the archives of thePythonDoc-SIG. Thanks to all members past & present.


Source:https://github.com/python/peps/blob/main/peps/pep-0256.rst

Last modified:2025-02-01 08:59:27 GMT


[8]ページ先頭

©2009-2026 Movatter.jp