Debian Codegraph @

docs/dev/semantics.rst

raw
1 .. include:: ../header.rst
2
3 =====================
4 Docstring Semantics
5 =====================
6 :Author: David Goodger
7 :Contact: [email protected]
8 :Revision: $Revision: 9906 $
9 :Date: $Date: 2024-08-15 10:43:38 +0200 (Do, 15. Aug 2024) $
10 :Copyright: This document has been placed in the public domain.
11
12 These are notes for a possible future PEP providing the final piece of
13 the Python docstring puzzle: docstring semantics or documentation
14 methodology. `PEP 257`_, Docstring Conventions, sketches out some
15 guidelines, but does not get into methodology details.
16
17 I haven't explored documentation methodology more because, in my
18 opinion, it is a completely separate issue from syntax, and it's even
19 more controversial than syntax. Nobody wants to be told how to lay
20 out their documentation, a la JavaDoc_. I think the JavaDoc way is
21 butt-ugly, but it *is* an established standard for the Java world.
22 Any standard documentation methodology has to be formal enough to be
23 useful but remain light enough to be usable. If the methodology is
24 too strict, too heavy, or too ugly, many/most will not want to use it.
25
26 I think a standard methodology could benefit the Python community, but
27 it would be a hard sell. A PEP would be the place to start. For most
28 human-readable documentation needs, the free-form text approach is
29 adequate. We'd only need a formal methodology if we want to extract
30 the parameters into a data dictionary, index, or summary of some kind.
31
32
33 PythonDoc
34 =========
35
36 (Not to be confused with Daniel Larsson's pythondoc_ project.)
37
38 A Python version of the JavaDoc_ semantics (not syntax). A set of
39 conventions which are understood by the Docutils. What JavaDoc has
40 done is to establish a syntax that enables a certain documentation
41 methodology, or standard *semantics*. JavaDoc is not just syntax; it
42 prescribes a methodology.
43
44 - Use field lists or definition lists for "tagged blocks". By this I
45 mean that field lists can be used similarly to JavaDoc's ``@tag``
46 syntax. That's actually one of the motivators behind field lists.
47 For example, we could have::
48
49 """
50 :Parameters:
51 - `lines`: a list of one-line strings without newlines.
52 - `until_blank`: Stop collecting at the first blank line if
53 true (1).
54 - `strip_indent`: Strip common leading indent if true (1,
55 default).
56
57 :Return:
58 - a list of indented lines with minimum indent removed;
59 - the amount of the indent;
60 - whether or not the block finished with a blank line or at
61 the end of `lines`.
62 """
63
64 This is taken straight out of docutils/statemachine.py, in which I
65 experimented with a simple documentation methodology. Another
66 variation I've thought of exploits the Grouch_-compatible
67 "classifier" element of definition lists. For example::
68
69 :Parameters:
70 `lines` : [string]
71 List of one-line strings without newlines.
72 `until_blank` : boolean
73 Stop collecting at the first blank line if true (1).
74 `strip_indent` : boolean
75 Strip common leading indent if true (1, default).
76
77 - Field lists could even be used in a one-to-one correspondence with
78 JavaDoc ``@tags``, although I doubt if I'd recommend it. Several
79 ports of JavaDoc's ``@tag`` methodology exist in Python, most
80 recently Ed Loper's "epydoc_".
81
82
83 Other Ideas
84 ===========
85
86 - Can we extract comments from parsed modules? Could be handy for
87 documenting function/method parameters::
88
89 def method(self,
90 source, # path of input file
91 dest # path of output file
92 ):
93
94 This would save having to repeat parameter names in the docstring.
95
96 Idea from Mark Hammond's 1998-06-23 Doc-SIG post, "Re: [Doc-SIG]
97 Documentation tool":
98
99 it would be quite hard to add a new param to this method without
100 realising you should document it
101
102 - Frederic Giacometti's `iPhrase Python documentation conventions`_ is
103 an attachment to his Doc-SIG post of 2001-05-30.
104
105
106 .. _PEP 257: https://peps.python.org/pep-0257
107 .. _JavaDoc: http://java.sun.com/j2se/javadoc/
108 .. _pythondoc: http://starship.python.net/crew/danilo/pythondoc/
109 .. _Grouch: http://www.mems-exchange.org/software/grouch/
110 .. _epydoc: http://epydoc.sourceforge.net/
111 .. _iPhrase Python documentation conventions:
112 https://mail.python.org/pipermail/doc-sig/2001-May/001840.html
113
114 .. Emacs settings
115
116 Local Variables:
117 mode: indented-text
118 mode: rst
119 indent-tabs-mode: nil
120 sentence-end-double-space: t
121 fill-column: 70
122 End: