@@ -59,224 +59,6 @@ gladly work with you to integrate your text, dealing with the markup for you.
59
59
Please don't let the material in this document stand between the documentation
60
60
and your desire to help out!
61
61
62
- .. _style-guide :
63
-
64
- Style guide
65
- ===========
66
-
67
- Use of whitespace
68
- -----------------
69
-
70
- All reST files use an indentation of 3 spaces; no tabs are allowed. The
71
- maximum line length is 80 characters for normal text, but tables, deeply
72
- indented code samples and long links may extend beyond that. Code example
73
- bodies should use normal Python 4-space indentation.
74
-
75
- Make generous use of blank lines where applicable; they help group things
76
- together.
77
-
78
- A sentence-ending period may be followed by one or two spaces; while reST
79
- ignores the second space, it is customarily put in by some users, for example
80
- to aid Emacs' auto-fill mode.
81
-
82
- Footnotes
83
- ---------
84
-
85
- Footnotes are generally discouraged, though they may be used when they are the
86
- best way to present specific information. When a footnote reference is added at
87
- the end of the sentence, it should follow the sentence-ending punctuation. The
88
- reST markup should appear something like this::
89
-
90
- This sentence has a footnote reference. [#]_ This is the next sentence.
91
-
92
- Footnotes should be gathered at the end of a file, or if the file is very long,
93
- at the end of a section. The docutils will automatically create backlinks to
94
- the footnote reference.
95
-
96
- Footnotes may appear in the middle of sentences where appropriate.
97
-
98
- Capitalization
99
- --------------
100
-
101
- .. sidebar :: Sentence case
102
-
103
- Sentence case is a set of capitalization rules used in English
104
- sentences: the first word is always capitalized and other words are
105
- only capitalized if there is a specific rule requiring it.
106
-
107
- In the Python documentation, the use of sentence case in section titles is
108
- preferable, but consistency within a unit is more important than
109
- following this rule. If you add a section to a chapter where most
110
- sections are in title case, you can either convert all titles to
111
- sentence case or use the dominant style in the new section title.
112
-
113
- Sentences that start with a word for which specific rules require
114
- starting it with a lower case letter should be avoided.
115
-
116
- .. note ::
117
-
118
- Sections that describe a library module often have titles in the
119
- form of "modulename --- Short description of the module." In this
120
- case, the description should be capitalized as a stand-alone
121
- sentence.
122
-
123
- Many special names are used in the Python documentation, including the names of
124
- operating systems, programming languages, standards bodies, and the like. Most
125
- of these entities are not assigned any special markup, but the preferred
126
- spellings are given here to aid authors in maintaining the consistency of
127
- presentation in the Python documentation.
128
-
129
- Other terms and words deserve special mention as well; these conventions should
130
- be used to ensure consistency throughout the documentation:
131
-
132
- CPU
133
- For "central processing unit." Many style guides say this should be
134
- spelled out on the first use (and if you must use it, do so!). For
135
- the Python documentation, this abbreviation should be avoided since
136
- there's no reasonable way to predict which occurrence will be the
137
- first seen by the reader. It is better to use the word "processor"
138
- instead.
139
-
140
- POSIX
141
- The name assigned to a particular group of standards. This is always
142
- uppercase.
143
-
144
- Python
145
- The name of our favorite programming language is always capitalized.
146
-
147
- reST
148
- For "reStructuredText," an easy to read, plaintext markup syntax
149
- used to produce Python documentation. When spelled out, it is
150
- always one word and both forms start with a lower case 'r'.
151
-
152
- Unicode
153
- The name of a character coding system. This is always written
154
- capitalized.
155
-
156
- Unix
157
- The name of the operating system developed at AT&T Bell Labs in the early
158
- 1970s.
159
-
160
- Affirmative Tone
161
- ----------------
162
-
163
- The documentation focuses on affirmatively stating what the language does and
164
- how to use it effectively.
165
-
166
- Except for certain security or segfault risks, the docs should avoid
167
- wording along the lines of "feature x is dangerous" or "experts only". These
168
- kinds of value judgments belong in external blogs and wikis, not in the core
169
- documentation.
170
-
171
- Bad example (creating worry in the mind of a reader):
172
-
173
- Warning: failing to explicitly close a file could result in lost data or
174
- excessive resource consumption. Never rely on reference counting to
175
- automatically close a file.
176
-
177
- Good example (establishing confident knowledge in the effective use of the
178
- language):
179
-
180
- A best practice for using files is use a try/finally pair to explicitly
181
- close a file after it is used. Alternatively, using a with-statement can
182
- achieve the same effect. This assures that files are flushed and file
183
- descriptor resources are released in a timely manner.
184
-
185
- Economy of Expression
186
- ---------------------
187
-
188
- More documentation is not necessarily better documentation. Err on the side
189
- of being succinct.
190
-
191
- It is an unfortunate fact that making documentation longer can be an impediment
192
- to understanding and can result in even more ways to misread or misinterpret the
193
- text. Long descriptions full of corner cases and caveats can create the
194
- impression that a function is more complex or harder to use than it actually is.
195
-
196
- Security Considerations (and Other Concerns)
197
- --------------------------------------------
198
-
199
- Some modules provided with Python are inherently exposed to security issues
200
- (e.g. shell injection vulnerabilities) due to the purpose of the module
201
- (e.g. :mod: `ssl `). Littering the documentation of these modules with red
202
- warning boxes for problems that are due to the task at hand, rather than
203
- specifically to Python's support for that task, doesn't make for a good
204
- reading experience.
205
-
206
- Instead, these security concerns should be gathered into a dedicated
207
- "Security Considerations" section within the module's documentation, and
208
- cross-referenced from the documentation of affected interfaces with a note
209
- similar to ``"Please refer to the :ref:`security-considerations` section
210
- for important information on how to avoid common mistakes." ``.
211
-
212
- Similarly, if there is a common error that affects many interfaces in a
213
- module (e.g. OS level pipe buffers filling up and stalling child processes),
214
- these can be documented in a "Common Errors" section and cross-referenced
215
- rather than repeated for every affected interface.
216
-
217
- Code Examples
218
- -------------
219
-
220
- Short code examples can be a useful adjunct to understanding. Readers can often
221
- grasp a simple example more quickly than they can digest a formal description in
222
- prose.
223
-
224
- People learn faster with concrete, motivating examples that match the context of
225
- a typical use case. For instance, the :meth: `str.rpartition ` method is better
226
- demonstrated with an example splitting the domain from a URL than it would be
227
- with an example of removing the last word from a line of Monty Python dialog.
228
-
229
- The ellipsis for the :py:data: `sys.ps2 ` secondary interpreter prompt should only
230
- be used sparingly, where it is necessary to clearly differentiate between input
231
- lines and output lines. Besides contributing visual clutter, it makes it
232
- difficult for readers to cut-and-paste examples so they can experiment with
233
- variations.
234
-
235
- Code Equivalents
236
- ----------------
237
-
238
- Giving pure Python code equivalents (or approximate equivalents) can be a useful
239
- adjunct to a prose description. A documenter should carefully weigh whether the
240
- code equivalent adds value.
241
-
242
- A good example is the code equivalent for :func: `all `. The short 4-line code
243
- equivalent is easily digested; it re-emphasizes the early-out behavior; and it
244
- clarifies the handling of the corner-case where the iterable is empty. In
245
- addition, it serves as a model for people wanting to implement a commonly
246
- requested alternative where :func: `all ` would return the specific object
247
- evaluating to False whenever the function terminates early.
248
-
249
- A more questionable example is the code for :func: `itertools.groupby `. Its code
250
- equivalent borders on being too complex to be a quick aid to understanding.
251
- Despite its complexity, the code equivalent was kept because it serves as a
252
- model to alternative implementations and because the operation of the "grouper"
253
- is more easily shown in code than in English prose.
254
-
255
- An example of when not to use a code equivalent is for the :func: `oct ` function.
256
- The exact steps in converting a number to octal doesn't add value for a user
257
- trying to learn what the function does.
258
-
259
- Audience
260
- --------
261
-
262
- The tone of the tutorial (and all the docs) needs to be respectful of the
263
- reader's intelligence. Don't presume that the readers are stupid. Lay out the
264
- relevant information, show motivating use cases, provide glossary links, and do
265
- your best to connect-the-dots, but don't talk down to them or waste their time.
266
-
267
- The tutorial is meant for newcomers, many of whom will be using the tutorial to
268
- evaluate the language as a whole. The experience needs to be positive and not
269
- leave the reader with worries that something bad will happen if they make a
270
- misstep. The tutorial serves as guide for intelligent and curious readers,
271
- saving details for the how-to guides and other sources.
272
-
273
- Be careful accepting requests for documentation changes from the rare but vocal
274
- category of reader who is looking for vindication for one of their programming
275
- errors ("I made a mistake, therefore the docs must be wrong ..."). Typically,
276
- the documentation wasn't consulted until after the error was made. It is
277
- unfortunate, but typically no documentation edit would have saved the user from
278
- making false assumptions about the language ("I was surprised by ...").
279
-
280
62
281
63
.. _rst-primer :
282
64
@@ -1832,11 +1614,16 @@ files in the root of the repository using the ``gettext_compact=0``
1832
1614
style.
1833
1615
1834
1616
1835
-
1836
1617
.. _docutils : https://docutils.sourceforge.io/
1837
1618
.. _python-docs-theme : https://pypi.org/project/python-docs-theme/
1838
1619
.. _Sphinx : https://www.sphinx-doc.org/
1839
1620
.. _virtualenv : https://virtualenv.pypa.io/
1840
1621
.. _blurb : https://pypi.org/project/blurb/
1841
1622
.. _translation_wg : https://wiki.python.org/psf/TranslationWG/Charter
1842
1623
.. _translation_ml : https://mail.python.org/mailman3/lists/translation.python.org/
1624
+
1625
+
1626
+ Style Guide
1627
+ ===========
1628
+
1629
+ Moved to :doc: `style-guide `
0 commit comments