summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-12-14 18:08:20 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-12-14 18:08:20 (GMT)
commit48eca67ab984e024acdc3ee175d247a30e2ea33f (patch)
tree40c3da59aba3fc1166e2ef0f40a12ef79f13cb8d
parenta63f268351ea8116c08f6b9ee1028f5eec3d5158 (diff)
downloadcpython-48eca67ab984e024acdc3ee175d247a30e2ea33f.zip
cpython-48eca67ab984e024acdc3ee175d247a30e2ea33f.tar.gz
cpython-48eca67ab984e024acdc3ee175d247a30e2ea33f.tar.bz2
Add line spacing for readability
-rw-r--r--Doc/library/collections.rst9
-rw-r--r--Lib/collections.py16
2 files changed, 16 insertions, 9 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index c335e40..d5f4283 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -385,18 +385,25 @@ Example::
>>> Point = namedtuple('Point', 'x y', verbose=True)
class Point(tuple):
'Point(x, y)'
+
__slots__ = ()
+
_fields = ('x', 'y')
+
def __new__(cls, x, y):
return tuple.__new__(cls, (x, y))
+
def __repr__(self):
return 'Point(x=%r, y=%r)' % self
+
def _asdict(self):
- 'Return a new dict mapping field names to their values'
+ 'Return a new dict which maps field names to their values'
return dict(zip(('x', 'y'), self))
+
def _replace(self, **kwds):
'Return a new Point object replacing specified fields with new values'
return Point(**dict(zip(('x', 'y'), self), **kwds))
+
x = property(itemgetter(0))
y = property(itemgetter(1))
diff --git a/Lib/collections.py b/Lib/collections.py
index 3521ad0..c3173db 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -59,19 +59,19 @@ def namedtuple(typename, field_names, verbose=False):
argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
template = '''class %(typename)s(tuple):
- '%(typename)s(%(argtxt)s)'
- __slots__ = ()
- _fields = property(lambda self: %(field_names)r)
+ '%(typename)s(%(argtxt)s)' \n
+ __slots__ = () \n
+ _fields = property(lambda self: %(field_names)r) \n
def __new__(cls, %(argtxt)s):
- return tuple.__new__(cls, (%(argtxt)s))
+ return tuple.__new__(cls, (%(argtxt)s)) \n
def __repr__(self):
- return '%(typename)s(%(reprtxt)s)' %% self
+ return '%(typename)s(%(reprtxt)s)' %% self \n
def _asdict(self, dict=dict, zip=zip):
- 'Return a new dict mapping field names to their values'
- return dict(zip(%(field_names)r, self))
+ 'Return a new dict which maps field names to their values'
+ return dict(zip(%(field_names)r, self)) \n
def _replace(self, **kwds):
'Return a new %(typename)s object replacing specified fields with new values'
- return %(typename)s(**dict(zip(%(field_names)r, self), **kwds)) \n''' % locals()
+ return %(typename)s(**dict(zip(%(field_names)r, self), **kwds)) \n\n''' % locals()
for i, name in enumerate(field_names):
template += ' %s = property(itemgetter(%d))\n' % (name, i)
if verbose: