diff options
author | Raymond Hettinger <python@rcn.com> | 2009-05-27 02:24:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-05-27 02:24:45 (GMT) |
commit | a68cad13aee2f3df45bde6f3217c02b9b270d2e5 (patch) | |
tree | 72fa10650da4427ad1014d531eae644af6803e60 /Lib/collections.py | |
parent | 55d8828f982d4b03ef25db61cf0b8b50f1d1cf76 (diff) | |
download | cpython-a68cad13aee2f3df45bde6f3217c02b9b270d2e5.zip cpython-a68cad13aee2f3df45bde6f3217c02b9b270d2e5.tar.gz cpython-a68cad13aee2f3df45bde6f3217c02b9b270d2e5.tar.bz2 |
Fix field name conflicts for named tuples.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r-- | Lib/collections.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/collections.py b/Lib/collections.py index cac1777..1e807af 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -229,8 +229,8 @@ def namedtuple(typename, field_names, verbose=False, rename=False): '%(typename)s(%(argtxt)s)' \n __slots__ = () \n _fields = %(field_names)r \n - def __new__(cls, %(argtxt)s): - return tuple.__new__(cls, (%(argtxt)s)) \n + def __new__(_cls, %(argtxt)s): + return _tuple.__new__(_cls, (%(argtxt)s)) \n @classmethod def _make(cls, iterable, new=tuple.__new__, len=len): 'Make a new %(typename)s object from a sequence or iterable' @@ -243,23 +243,23 @@ def namedtuple(typename, field_names, verbose=False, rename=False): def _asdict(self): 'Return a new OrderedDict which maps field names to their values' return OrderedDict(zip(self._fields, self)) \n - def _replace(self, **kwds): + def _replace(_self, **kwds): 'Return a new %(typename)s object replacing specified fields with new values' - result = self._make(map(kwds.pop, %(field_names)r, self)) + result = _self._make(map(kwds.pop, %(field_names)r, _self)) if kwds: raise ValueError('Got unexpected field names: %%r' %% kwds.keys()) return result \n def __getnewargs__(self): 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))\n' % (name, i) if verbose: print template # Execute the template string in a temporary namespace and # support tracing utilities by setting a value for frame.f_globals['__name__'] - namespace = dict(itemgetter=_itemgetter, __name__='namedtuple_%s' % typename, - OrderedDict=OrderedDict) + namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename, + OrderedDict=OrderedDict, _property=property, _tuple=tuple) try: exec template in namespace except SyntaxError, e: |