summaryrefslogtreecommitdiffstats
path: root/Doc
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 /Doc
parent41fe6155394edf0ef65d125b27ceb8d1e37f72d3 (diff)
downloadcpython-7b0d3c6d4bdcec8e6e984e174f476978d95b93fd.zip
cpython-7b0d3c6d4bdcec8e6e984e174f476978d95b93fd.tar.gz
cpython-7b0d3c6d4bdcec8e6e984e174f476978d95b93fd.tar.bz2
Add nice docstrings to namedtuples.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/collections.rst7
1 files changed, 5 insertions, 2 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index fee59cf..176975b 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -653,6 +653,7 @@ Example:
_fields = ('x', 'y')
<BLANKLINE>
def __new__(_cls, x, y):
+ 'Create a new instance of Point(x, y)'
return _tuple.__new__(_cls, (x, y))
<BLANKLINE>
@classmethod
@@ -664,6 +665,7 @@ Example:
return result
<BLANKLINE>
def __repr__(self):
+ 'Return a nicely formatted representation string'
return 'Point(x=%r, y=%r)' % self
<BLANKLINE>
def _asdict(self):
@@ -678,10 +680,11 @@ Example:
return result
<BLANKLINE>
def __getnewargs__(self):
+ 'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self)
<BLANKLINE>
- x = _property(_itemgetter(0))
- y = _property(_itemgetter(1))
+ x = _property(_itemgetter(0), doc='Alias for field number 0')
+ y = _property(_itemgetter(1), doc='Alias for field number 1')
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
>>> p[0] + p[1] # indexable like the plain tuple (11, 22)