diff options
author | Raymond Hettinger <python@rcn.com> | 2011-03-22 21:21:38 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-03-22 21:21:38 (GMT) |
commit | 3e82ae0aae06d11b5bc345d87b57d551cab9d1eb (patch) | |
tree | ebea8dae7e4176863cab5bf62ab5fa14b48ccd92 /Lib/collections | |
parent | 9a3f4cbfc338e1d3da5619b709af1d005db26ac1 (diff) | |
download | cpython-3e82ae0aae06d11b5bc345d87b57d551cab9d1eb.zip cpython-3e82ae0aae06d11b5bc345d87b57d551cab9d1eb.tar.gz cpython-3e82ae0aae06d11b5bc345d87b57d551cab9d1eb.tar.bz2 |
Replace **locals() with explicit field names.
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index fd39ca8..8671330 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -288,9 +288,6 @@ def namedtuple(typename, field_names, verbose=False, rename=False): seen_names.add(name) # Create and fill-in the class template - numfields = len(field_names) - argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes - reprtxt = ', '.join('{}=%r'.format(name) for name in field_names) template = '''class {typename}(tuple): '{typename}({argtxt})' @@ -329,7 +326,14 @@ def namedtuple(typename, field_names, verbose=False, rename=False): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) -'''.format(**locals()) +''' + template = template.format( + typename = typename, + field_names = field_names, + argtxt = repr(field_names).replace("'", "")[1:-1], + numfields = len(field_names), + reprtxt = ', '.join('{}=%r'.format(name) for name in field_names), + ) for i, name in enumerate(field_names): template += " %s = _property(_itemgetter(%d), doc='Alias for field number %d')\n" % (name, i, i) if verbose: |