Skip to content

Commit c499f30

Browse files
Issue python#23921: Standardized documentation whitespace formatting.
Original patch by James Edwards.
2 parents a4dfbe6 + dba9039 commit c499f30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+449
-413
lines changed

Doc/distutils/apiref.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,9 +1907,9 @@ Subclasses of :class:`Command` must define the following methods.
19071907
that is designed to run with both Python 2.x and 3.x, add::
19081908

19091909
try:
1910-
from distutils.command.build_py import build_py_2to3 as build_py
1910+
from distutils.command.build_py import build_py_2to3 as build_py
19111911
except ImportError:
1912-
from distutils.command.build_py import build_py
1912+
from distutils.command.build_py import build_py
19131913

19141914
to your setup.py, and later::
19151915

Doc/faq/design.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ where in Python you're forced to write this::
158158
line = f.readline()
159159
if not line:
160160
break
161-
... # do something with line
161+
... # do something with line
162162

163163
The reason for not allowing assignment in Python expressions is a common,
164164
hard-to-find bug in those other languages, caused by this construct:
@@ -190,7 +190,7 @@ generally less robust than the "while True" solution::
190190

191191
line = f.readline()
192192
while line:
193-
... # do something with line...
193+
... # do something with line...
194194
line = f.readline()
195195

196196
The problem with this is that if you change your mind about exactly how you get
@@ -203,7 +203,7 @@ objects using the ``for`` statement. For example, :term:`file objects
203203
<file object>` support the iterator protocol, so you can write simply::
204204

205205
for line in f:
206-
... # do something with line...
206+
... # do something with line...
207207

208208

209209

@@ -577,8 +577,10 @@ other structure). ::
577577
class ListWrapper:
578578
def __init__(self, the_list):
579579
self.the_list = the_list
580+
580581
def __eq__(self, other):
581582
return self.the_list == other.the_list
583+
582584
def __hash__(self):
583585
l = self.the_list
584586
result = 98767 - len(l)*555
@@ -619,7 +621,7 @@ it and returns it. For example, here's how to iterate over the keys of a
619621
dictionary in sorted order::
620622

621623
for key in sorted(mydict):
622-
... # do whatever with mydict[key]...
624+
... # do whatever with mydict[key]...
623625

624626

625627
How do you specify and enforce an interface spec in Python?
@@ -675,11 +677,11 @@ languages. For example::
675677
class label(Exception): pass # declare a label
676678

677679
try:
678-
...
679-
if condition: raise label() # goto label
680-
...
680+
...
681+
if condition: raise label() # goto label
682+
...
681683
except label: # where to goto
682-
pass
684+
pass
683685
...
684686

685687
This doesn't allow you to jump into the middle of a loop, but that's usually

Doc/faq/library.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ all the threads to finish::
257257
import threading, time
258258

259259
def thread_task(name, n):
260-
for i in range(n): print(name, i)
260+
for i in range(n):
261+
print(name, i)
261262

262263
for i in range(10):
263264
T = threading.Thread(target=thread_task, args=(str(i), i))
@@ -273,7 +274,8 @@ A simple fix is to add a tiny sleep to the start of the run function::
273274

274275
def thread_task(name, n):
275276
time.sleep(0.001) # <--------------------!
276-
for i in range(n): print(name, i)
277+
for i in range(n):
278+
print(name, i)
277279

278280
for i in range(10):
279281
T = threading.Thread(target=thread_task, args=(str(i), i))
@@ -502,8 +504,8 @@ in big-endian format from a file::
502504
import struct
503505

504506
with open(filename, "rb") as f:
505-
s = f.read(8)
506-
x, y, z = struct.unpack(">hhl", s)
507+
s = f.read(8)
508+
x, y, z = struct.unpack(">hhl", s)
507509

508510
The '>' in the format string forces big-endian data; the letter 'h' reads one
509511
"short integer" (2 bytes), and 'l' reads one "long integer" (4 bytes) from the
@@ -681,10 +683,10 @@ Yes. Here's a simple example that uses urllib.request::
681683

682684
import urllib.request
683685

684-
### build the query string
686+
# build the query string
685687
qs = "First=Josephine&MI=Q&Last=Public"
686688

687-
### connect and send the server a path
689+
# connect and send the server a path
688690
req = urllib.request.urlopen('http://www.some-server.out-there'
689691
'/cgi-bin/some-cgi-script', data=qs)
690692
with req:
@@ -740,8 +742,9 @@ varies between systems; sometimes it is ``/usr/lib/sendmail``, sometimes
740742
``/usr/sbin/sendmail``. The sendmail manual page will help you out. Here's
741743
some sample code::
742744

743-
SENDMAIL = "/usr/sbin/sendmail" # sendmail location
744745
import os
746+
747+
SENDMAIL = "/usr/sbin/sendmail" # sendmail location
745748
p = os.popen("%s -t -i" % SENDMAIL, "w")
746749
p.write("To: receiver@example.com\n")
747750
p.write("Subject: test\n")

Doc/faq/programming.rst

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ functions), e.g.::
207207

208208
>>> squares = []
209209
>>> for x in range(5):
210-
... squares.append(lambda: x**2)
210+
... squares.append(lambda: x**2)
211211

212212
This gives you a list that contains 5 lambdas that calculate ``x**2``. You
213213
might expect that, when called, they would return, respectively, ``0``, ``1``,
@@ -234,7 +234,7 @@ lambdas, so that they don't rely on the value of the global ``x``::
234234

235235
>>> squares = []
236236
>>> for x in range(5):
237-
... squares.append(lambda n=x: n**2)
237+
... squares.append(lambda n=x: n**2)
238238

239239
Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed
240240
when the lambda is defined so that it has the same value that ``x`` had at
@@ -539,7 +539,7 @@ desired effect in a number of ways.
539539
args['a'] = 'new-value' # args is a mutable dictionary
540540
args['b'] = args['b'] + 1 # change it in-place
541541

542-
args = {'a':' old-value', 'b': 99}
542+
args = {'a': 'old-value', 'b': 99}
543543
func3(args)
544544
print(args['a'], args['b'])
545545

@@ -655,16 +655,15 @@ Essentially, assignment always binds a name to a value; The same is true of
655655
``def`` and ``class`` statements, but in that case the value is a
656656
callable. Consider the following code::
657657

658-
class A:
659-
pass
660-
661-
B = A
662-
663-
a = B()
664-
b = a
665-
print(b)
658+
>>> class A:
659+
... pass
660+
...
661+
>>> B = A
662+
>>> a = B()
663+
>>> b = a
664+
>>> print(b)
666665
<__main__.A object at 0x16D07CC>
667-
print(a)
666+
>>> print(a)
668667
<__main__.A object at 0x16D07CC>
669668

670669
Arguably the class has a name: even though it is bound to two names and invoked
@@ -1100,15 +1099,15 @@ How do I iterate over a sequence in reverse order?
11001099
Use the :func:`reversed` built-in function, which is new in Python 2.4::
11011100

11021101
for x in reversed(sequence):
1103-
... # do something with x...
1102+
... # do something with x ...
11041103

11051104
This won't touch your original sequence, but build a new copy with reversed
11061105
order to iterate over.
11071106

11081107
With Python 2.3, you can use an extended slice syntax::
11091108

11101109
for x in sequence[::-1]:
1111-
... # do something with x...
1110+
... # do something with x ...
11121111

11131112

11141113
How do you remove duplicates from a list?
@@ -1406,7 +1405,7 @@ A method is a function on some object ``x`` that you normally call as
14061405
definition::
14071406

14081407
class C:
1409-
def meth (self, arg):
1408+
def meth(self, arg):
14101409
return arg * 2 + self.attribute
14111410

14121411

@@ -1439,21 +1438,21 @@ that does something::
14391438

14401439
def search(obj):
14411440
if isinstance(obj, Mailbox):
1442-
# ... code to search a mailbox
1441+
... # code to search a mailbox
14431442
elif isinstance(obj, Document):
1444-
# ... code to search a document
1443+
... # code to search a document
14451444
elif ...
14461445

14471446
A better approach is to define a ``search()`` method on all the classes and just
14481447
call it::
14491448

14501449
class Mailbox:
14511450
def search(self):
1452-
# ... code to search a mailbox
1451+
... # code to search a mailbox
14531452

14541453
class Document:
14551454
def search(self):
1456-
# ... code to search a document
1455+
... # code to search a document
14571456

14581457
obj.search()
14591458

@@ -1510,7 +1509,7 @@ How do I call a method defined in a base class from a derived class that overrid
15101509
Use the built-in :func:`super` function::
15111510

15121511
class Derived(Base):
1513-
def meth (self):
1512+
def meth(self):
15141513
super(Derived, self).meth()
15151514

15161515
For version prior to 3.0, you may be using classic classes: For a class

Doc/howto/descriptor.rst

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ like::
104104
"Emulate type_getattro() in Objects/typeobject.c"
105105
v = object.__getattribute__(self, key)
106106
if hasattr(v, '__get__'):
107-
return v.__get__(None, self)
107+
return v.__get__(None, self)
108108
return v
109109

110110
The important points to remember are:
@@ -163,9 +163,9 @@ descriptor is useful for monitoring just a few chosen attributes::
163163
self.val = val
164164

165165
>>> class MyClass(object):
166-
x = RevealAccess(10, 'var "x"')
167-
y = 5
168-
166+
... x = RevealAccess(10, 'var "x"')
167+
... y = 5
168+
...
169169
>>> m = MyClass()
170170
>>> m.x
171171
Retrieving var "x"
@@ -287,15 +287,15 @@ this::
287287
Running the interpreter shows how the function descriptor works in practice::
288288

289289
>>> class D(object):
290-
def f(self, x):
291-
return x
292-
290+
... def f(self, x):
291+
... return x
292+
...
293293
>>> d = D()
294-
>>> D.__dict__['f'] # Stored internally as a function
294+
>>> D.__dict__['f'] # Stored internally as a function
295295
<function f at 0x00C45070>
296-
>>> D.f # Get from a class becomes an unbound method
296+
>>> D.f # Get from a class becomes an unbound method
297297
<unbound method D.f>
298-
>>> d.f # Get from an instance becomes a bound method
298+
>>> d.f # Get from an instance becomes a bound method
299299
<bound method D.f of <__main__.D object at 0x00B18C90>>
300300

301301
The output suggests that bound and unbound methods are two different types.
@@ -358,10 +358,10 @@ Since staticmethods return the underlying function with no changes, the example
358358
calls are unexciting::
359359

360360
>>> class E(object):
361-
def f(x):
362-
print(x)
363-
f = staticmethod(f)
364-
361+
... def f(x):
362+
... print(x)
363+
... f = staticmethod(f)
364+
...
365365
>>> print(E.f(3))
366366
3
367367
>>> print(E().f(3))
@@ -371,23 +371,23 @@ Using the non-data descriptor protocol, a pure Python version of
371371
:func:`staticmethod` would look like this::
372372

373373
class StaticMethod(object):
374-
"Emulate PyStaticMethod_Type() in Objects/funcobject.c"
374+
"Emulate PyStaticMethod_Type() in Objects/funcobject.c"
375375

376-
def __init__(self, f):
377-
self.f = f
376+
def __init__(self, f):
377+
self.f = f
378378

379-
def __get__(self, obj, objtype=None):
380-
return self.f
379+
def __get__(self, obj, objtype=None):
380+
return self.f
381381

382382
Unlike static methods, class methods prepend the class reference to the
383383
argument list before calling the function. This format is the same
384384
for whether the caller is an object or a class::
385385

386386
>>> class E(object):
387-
def f(klass, x):
388-
return klass.__name__, x
389-
f = classmethod(f)
390-
387+
... def f(klass, x):
388+
... return klass.__name__, x
389+
... f = classmethod(f)
390+
...
391391
>>> print(E.f(3))
392392
('E', 3)
393393
>>> print(E().f(3))
@@ -419,15 +419,15 @@ Using the non-data descriptor protocol, a pure Python version of
419419
:func:`classmethod` would look like this::
420420

421421
class ClassMethod(object):
422-
"Emulate PyClassMethod_Type() in Objects/funcobject.c"
422+
"Emulate PyClassMethod_Type() in Objects/funcobject.c"
423423

424-
def __init__(self, f):
425-
self.f = f
424+
def __init__(self, f):
425+
self.f = f
426426

427-
def __get__(self, obj, klass=None):
428-
if klass is None:
429-
klass = type(obj)
430-
def newfunc(*args):
431-
return self.f(klass, *args)
432-
return newfunc
427+
def __get__(self, obj, klass=None):
428+
if klass is None:
429+
klass = type(obj)
430+
def newfunc(*args):
431+
return self.f(klass, *args)
432+
return newfunc
433433

Doc/howto/functional.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,14 @@ equivalent to the following Python code::
395395
continue # Skip this element
396396
for expr2 in sequence2:
397397
if not (condition2):
398-
continue # Skip this element
398+
continue # Skip this element
399399
...
400400
for exprN in sequenceN:
401-
if not (conditionN):
402-
continue # Skip this element
401+
if not (conditionN):
402+
continue # Skip this element
403403

404-
# Output the value of
405-
# the expression.
404+
# Output the value of
405+
# the expression.
406406

407407
This means that when there are multiple ``for...in`` clauses but no ``if``
408408
clauses, the length of the resulting output will be equal to the product of the

0 commit comments

Comments
 (0)