summaryrefslogtreecommitdiff
path: root/Lib/collections/__init__.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-03-22 13:34:03 -0700
committerRaymond Hettinger <python@rcn.com>2011-03-22 13:34:03 -0700
commit56e5c84908356961c8c05ad46c3d1e27b8ea63da (patch)
tree391f1b26cd065ef94104d0f0ca93d2c336f38c8a /Lib/collections/__init__.py
parent92a984a8aff0dcf645134e3d9c2498739652dbe5 (diff)
downloadcpython-56e5c84908356961c8c05ad46c3d1e27b8ea63da.tar.gz
Improve readability by replacing '\n' in template with real newlines.
Diffstat (limited to 'Lib/collections/__init__.py')
-rw-r--r--Lib/collections/__init__.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index c324ce3bd6..dcb11c0bfd 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -292,34 +292,44 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
template = '''class %(typename)s(tuple):
- '%(typename)s(%(argtxt)s)' \n
- __slots__ = () \n
- _fields = %(field_names)r \n
+ '%(typename)s(%(argtxt)s)'
+
+ __slots__ = ()
+
+ _fields = %(field_names)r
+
def __new__(_cls, %(argtxt)s):
'Create new instance of %(typename)s(%(argtxt)s)'
- return _tuple.__new__(_cls, (%(argtxt)s)) \n
+ return _tuple.__new__(_cls, (%(argtxt)s))
+
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
'Make a new %(typename)s object from a sequence or iterable'
result = new(cls, iterable)
if len(result) != %(numfields)d:
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
- return result \n
+ return result
+
def __repr__(self):
'Return a nicely formatted representation string'
- return self.__class__.__name__ + '(%(reprtxt)s)' %% self \n
+ return self.__class__.__name__ + '(%(reprtxt)s)' %% self
+
def _asdict(self):
'Return a new OrderedDict which maps field names to their values'
- return OrderedDict(zip(self._fields, self)) \n
+ return OrderedDict(zip(self._fields, self))
+
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))
if kwds:
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
- return result \n
+ return result
+
def __getnewargs__(self):
'Return self as a plain tuple. Used by copy and pickle.'
- return tuple(self) \n\n''' % locals()
+ return tuple(self)
+
+ ''' % locals()
for i, name in enumerate(field_names):
template += " %s = _property(_itemgetter(%d), doc='Alias for field number %d')\n" % (name, i, i)
if verbose: