Issue #23921: Standardized documentation whitespace formatting.
Original patch by James Edwards.
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst
index 3f4a04b..1e523d4 100644
--- a/Doc/faq/design.rst
+++ b/Doc/faq/design.rst
@@ -169,7 +169,7 @@
line = f.readline()
if not line:
break
- ... # do something with line
+ ... # do something with line
The reason for not allowing assignment in Python expressions is a common,
hard-to-find bug in those other languages, caused by this construct:
@@ -201,7 +201,7 @@
line = f.readline()
while line:
- ... # do something with line...
+ ... # do something with line...
line = f.readline()
The problem with this is that if you change your mind about exactly how you get
@@ -214,7 +214,7 @@
Python file objects support the iterator protocol, so you can now write simply::
for line in f:
- ... # do something with line...
+ ... # do something with line...
@@ -625,8 +625,10 @@
class ListWrapper:
def __init__(self, the_list):
self.the_list = the_list
+
def __eq__(self, other):
return self.the_list == other.the_list
+
def __hash__(self):
l = self.the_list
result = 98767 - len(l)*555
@@ -667,7 +669,7 @@
order::
for key in sorted(mydict):
- ... # do whatever with mydict[key]...
+ ... # do whatever with mydict[key]...
How do you specify and enforce an interface spec in Python?
@@ -723,11 +725,11 @@
class label: pass # declare a label
try:
- ...
- if condition: raise label() # goto label
- ...
+ ...
+ if condition: raise label() # goto label
+ ...
except label: # where to goto
- pass
+ pass
...
This doesn't allow you to jump into the middle of a loop, but that's usually
diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst
index c5fa4c2..d1b3efb 100644
--- a/Doc/faq/library.rst
+++ b/Doc/faq/library.rst
@@ -658,20 +658,20 @@
import httplib, sys, time
- ### build the query string
+ # build the query string
qs = "First=Josephine&MI=Q&Last=Public"
- ### connect and send the server a path
+ # connect and send the server a path
httpobj = httplib.HTTP('www.some-server.out-there', 80)
httpobj.putrequest('POST', '/cgi-bin/some-cgi-script')
- ### now generate the rest of the HTTP headers...
+ # now generate the rest of the HTTP headers...
httpobj.putheader('Accept', '*/*')
httpobj.putheader('Connection', 'Keep-Alive')
httpobj.putheader('Content-type', 'application/x-www-form-urlencoded')
httpobj.putheader('Content-length', '%d' % len(qs))
httpobj.endheaders()
httpobj.send(qs)
- ### find out what the server said in response...
+ # find out what the server said in response...
reply, msg, hdrs = httpobj.getreply()
if reply != 200:
sys.stdout.write(httpobj.getfile().read())
@@ -724,8 +724,9 @@
``/usr/sbin/sendmail``. The sendmail manual page will help you out. Here's
some sample code::
- SENDMAIL = "/usr/sbin/sendmail" # sendmail location
import os
+
+ SENDMAIL = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t -i" % SENDMAIL, "w")
p.write("To: receiver@example.com\n")
p.write("Subject: test\n")
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 4578280..d83833d 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -353,7 +353,7 @@
>>> squares = []
>>> for x in range(5):
- ... squares.append(lambda: x**2)
+ ... squares.append(lambda: x**2)
This gives you a list that contains 5 lambdas that calculate ``x**2``. You
might expect that, when called, they would return, respectively, ``0``, ``1``,
@@ -380,7 +380,7 @@
>>> squares = []
>>> for x in range(5):
- ... squares.append(lambda n=x: n**2)
+ ... squares.append(lambda n=x: n**2)
Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed
when the lambda is defined so that it has the same value that ``x`` had at
@@ -699,7 +699,7 @@
args['a'] = 'new-value' # args is a mutable dictionary
args['b'] = args['b'] + 1 # change it in-place
- args = {'a':' old-value', 'b': 99}
+ args = {'a': 'old-value', 'b': 99}
func3(args)
print args['a'], args['b']
@@ -815,16 +815,15 @@
``def`` and ``class`` statements, but in that case the value is a
callable. Consider the following code::
- class A:
- pass
-
- B = A
-
- a = B()
- b = a
- print b
+ >>> class A:
+ ... pass
+ ...
+ >>> B = A
+ >>> a = B()
+ >>> b = a
+ >>> print b
<__main__.A instance at 0x16D07CC>
- print a
+ >>> print a
<__main__.A instance at 0x16D07CC>
Arguably the class has a name: even though it is bound to two names and invoked
@@ -1209,7 +1208,7 @@
Use the :func:`reversed` built-in function, which is new in Python 2.4::
for x in reversed(sequence):
- ... # do something with x...
+ ... # do something with x ...
This won't touch your original sequence, but build a new copy with reversed
order to iterate over.
@@ -1217,7 +1216,7 @@
With Python 2.3, you can use an extended slice syntax::
for x in sequence[::-1]:
- ... # do something with x...
+ ... # do something with x ...
How do you remove duplicates from a list?
@@ -1552,7 +1551,7 @@
definition::
class C:
- def meth (self, arg):
+ def meth(self, arg):
return arg * 2 + self.attribute
@@ -1585,9 +1584,9 @@
def search(obj):
if isinstance(obj, Mailbox):
- # ... code to search a mailbox
+ ... # code to search a mailbox
elif isinstance(obj, Document):
- # ... code to search a document
+ ... # code to search a document
elif ...
A better approach is to define a ``search()`` method on all the classes and just
@@ -1595,11 +1594,11 @@
class Mailbox:
def search(self):
- # ... code to search a mailbox
+ ... # code to search a mailbox
class Document:
def search(self):
- # ... code to search a document
+ ... # code to search a document
obj.search()
@@ -1656,7 +1655,7 @@
If you're using new-style classes, use the built-in :func:`super` function::
class Derived(Base):
- def meth (self):
+ def meth(self):
super(Derived, self).meth()
If you're using classic classes: For a class definition such as ``class