mirror of https://github.com/python/cpython
Speed-up named tuple's _make() constructor.
This commit is contained in:
parent
35f8861386
commit
844f71b7e4
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue