From 3e82ae0aae06d11b5bc345d87b57d551cab9d1eb Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 22 Mar 2011 14:21:38 -0700 Subject: [PATCH] Replace **locals() with explicit field names. --- Lib/collections/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index fd39ca8052e..86713303e5c 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: