Merged revisions 59843-59863 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59844 | raymond.hettinger | 2008-01-07 21:56:05 +0100 (Mon, 07 Jan 2008) | 1 line
Use get() instead of pop() for the optimized version of _replace().
........
r59847 | raymond.hettinger | 2008-01-07 22:33:51 +0100 (Mon, 07 Jan 2008) | 1 line
Documentation nits.
........
r59849 | raymond.hettinger | 2008-01-08 03:02:05 +0100 (Tue, 08 Jan 2008) | 1 line
Expand comment.
........
r59850 | raymond.hettinger | 2008-01-08 03:24:15 +0100 (Tue, 08 Jan 2008) | 1 line
Docs on named tuple's naming conventions and limits of subclassing
........
r59851 | christian.heimes | 2008-01-08 04:40:04 +0100 (Tue, 08 Jan 2008) | 1 line
It's verbose, not debug
........
r59852 | facundo.batista | 2008-01-08 13:25:20 +0100 (Tue, 08 Jan 2008) | 4 lines
Issue #1757: The hash of a Decimal instance is no longer affected
by the current context. Thanks Mark Dickinson.
........
r59853 | andrew.kuchling | 2008-01-08 15:30:55 +0100 (Tue, 08 Jan 2008) | 1 line
Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
........
r59854 | andrew.kuchling | 2008-01-08 15:56:02 +0100 (Tue, 08 Jan 2008) | 1 line
Patch 1114: fix compilation of curses module on 64-bit AIX, and any other LP64 platforms where attr_t isn't a C long
........
r59856 | thomas.heller | 2008-01-08 16:15:09 +0100 (Tue, 08 Jan 2008) | 5 lines
Use relative instead of absolute filenames in the C-level tracebacks.
This prevents traceback prints pointing to files in this way:
File "\loewis\25\python\Modules\_ctypes\callbacks.c", line 206, in 'calling callback function'
........
r59857 | christian.heimes | 2008-01-08 16:46:10 +0100 (Tue, 08 Jan 2008) | 2 lines
Added __enter__ and __exit__ functions to HKEY object
Added ExpandEnvironmentStrings to the _winreg module.
........
r59858 | georg.brandl | 2008-01-08 17:18:26 +0100 (Tue, 08 Jan 2008) | 2 lines
Fix markup errors from r59857 and clarify key.__enter__/__exit__ docs
........
r59860 | georg.brandl | 2008-01-08 20:42:30 +0100 (Tue, 08 Jan 2008) | 2 lines
Better method for associating .py files with the interpreter.
........
r59862 | facundo.batista | 2008-01-08 22:10:12 +0100 (Tue, 08 Jan 2008) | 9 lines
Issue 846388. Adds a call to PyErr_CheckSignals to
SRE_MATCH so that signal handlers can be invoked during
long regular expression matches. It also adds a new
error return value indicating that an exception
occurred in a signal handler during the match, allowing
exceptions in the signal handler to propagate up to the
main loop. Thanks Josh Hoyt and Ralf Schmitt.
........
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 2b8e279..0c440d6 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -397,8 +397,8 @@
method which lists the tuple contents in a ``name=value`` format.
The *fieldnames* are a single string with each fieldname separated by whitespace
- and/or commas (for example 'x y' or 'x, y'). Alternatively, the *fieldnames*
- can be specified with a sequence of strings (such as ['x', 'y']).
+ and/or commas (for example 'x y' or 'x, y'). Alternatively, *fieldnames*
+ can be a sequence of strings (such as ['x', 'y']).
Any valid Python identifier may be used for a fieldname except for names
starting with an underscore. Valid identifiers consist of letters, digits,
@@ -477,7 +477,8 @@
print emp.name, emp.title
In addition to the methods inherited from tuples, named tuples support
-three additional methods and one attribute.
+three additional methods and one attribute. To prevent conflicts with
+field names, the method and attribute names start with an underscore.
.. method:: somenamedtuple._make(iterable)
@@ -513,7 +514,7 @@
.. attribute:: somenamedtuple._fields
- Tuple of strings listing the field names. This is useful for introspection
+ Tuple of strings listing the field names. Useful for introspection
and for creating new named tuple types from existing named tuples.
::
@@ -532,7 +533,7 @@
>>> getattr(p, 'x')
11
-When casting a dictionary to a named tuple, use the double-star-operator [#]_::
+To cast a dictionary to a named tuple, use the double-star-operator [#]_::
>>> d = {'x': 11, 'y': 22}
>>> Point(**d)
@@ -557,14 +558,20 @@
Point: x= 1.286 y= 6.000 hypot= 6.136
Another use for subclassing is to replace performance critcal methods with
-faster versions that bypass error-checking and localize variable access::
+faster versions that bypass error-checking and that localize variable access::
>>> class Point(namedtuple('Point', 'x y')):
_make = classmethod(tuple.__new__)
def _replace(self, _map=map, **kwds):
- return self._make(_map(kwds.pop, ('x', 'y'), self))
+ return self._make(_map(kwds.get, ('x', 'y'), self))
-Default values can be implemented by using :meth:`_replace`:: to
+
+Subclassing is not useful for adding new, stored fields. Instead, simply
+create a new named tuple type from the :attr:`_fields` attribute::
+
+ >>> Pixel = namedtuple('Pixel', Point._fields + Color._fields)
+
+Default values can be implemented by using :meth:`_replace` to
customize a prototype instance::
>>> Account = namedtuple('Account', 'owner balance transaction_count')