]> granicus.if.org Git - python/commitdiff
Speed-up named tuple's _make() constructor.
authorRaymond Hettinger <python@rcn.com>
Sun, 6 Jan 2008 22:11:54 +0000 (22:11 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 6 Jan 2008 22:11:54 +0000 (22:11 +0000)
Lib/collections.py

index 39b9229f578d3a4940fdd7c4f678a02bd3260eff..0b8689850270d35f734d14e89fa420252ba42e6f 100644 (file)
@@ -65,9 +65,9 @@ def namedtuple(typename, field_names, verbose=False):
         def __new__(cls, %(argtxt)s):
             return tuple.__new__(cls, (%(argtxt)s)) \n
         @classmethod
-        def _make(cls, iterable):
+        def _make(cls, iterable, new=tuple.__new__, len=len):
             'Make a new %(typename)s object from a sequence or iterable'
-            result = tuple.__new__(cls, iterable)
+            result = new(cls, iterable)
             if len(result) != %(numfields)d:
                 raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
             return result \n