summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-02 18:54:02 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-04-02 18:54:02 (GMT)
commit7b0d3c6d4bdcec8e6e984e174f476978d95b93fd (patch)
treeb9b0e2a2b435aa26394814b298ec0609c52bbac6 /Lib
parent41fe6155394edf0ef65d125b27ceb8d1e37f72d3 (diff)
downloadcpython-7b0d3c6d4bdcec8e6e984e174f476978d95b93fd.zip
cpython-7b0d3c6d4bdcec8e6e984e174f476978d95b93fd.tar.gz
cpython-7b0d3c6d4bdcec8e6e984e174f476978d95b93fd.tar.bz2
Add nice docstrings to namedtuples.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/collections.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 3e01054..6ec062f 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -233,6 +233,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
__slots__ = () \n
_fields = %(field_names)r \n
def __new__(_cls, %(argtxt)s):
+ 'Create new instance of %(typename)s(%(argtxt)s)'
return _tuple.__new__(_cls, (%(argtxt)s)) \n
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
@@ -242,6 +243,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
return result \n
def __repr__(self):
+ 'Return a nicely formatted representation string'
return '%(typename)s(%(reprtxt)s)' %% self \n
def _asdict(self):
'Return a new OrderedDict which maps field names to their values'
@@ -253,9 +255,10 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
return result \n
def __getnewargs__(self):
+ 'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self) \n\n''' % locals()
for i, name in enumerate(field_names):
- template += ' %s = _property(_itemgetter(%d))\n' % (name, i)
+ template += " %s = _property(_itemgetter(%d), doc='Alias for field number %d')\n" % (name, i, i)
if verbose:
print(template)