[Python-checkins] cpython (2.7): Issue 21832: Require named tuple inputs to be exact strings

raymond.hettinger python-checkins at python.org
Tue Jun 24 22:49:39 CEST 2014


http://hg.python.org/cpython/rev/30063f97a44d
changeset:   91361:30063f97a44d
branch:      2.7
parent:      91352:e04eefef7820
user:        Raymond Hettinger <python at rcn.com>
date:        Tue Jun 24 13:49:24 2014 -0700
summary:
  Issue 21832:  Require named tuple inputs to be exact strings

files:
  Lib/collections.py |  3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)


diff --git a/Lib/collections.py b/Lib/collections.py
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -314,6 +314,7 @@
     if isinstance(field_names, basestring):
         field_names = field_names.replace(',', ' ').split()
     field_names = map(str, field_names)
+    typename = str(typename)
     if rename:
         seen = set()
         for index, name in enumerate(field_names):
@@ -326,6 +327,8 @@
                 field_names[index] = '_%d' % index
             seen.add(name)
     for name in [typename] + field_names:
+        if type(name) != str:
+            raise TypeError('Type names and field names must be strings')
         if not all(c.isalnum() or c=='_' for c in name):
             raise ValueError('Type names and field names can only contain '
                              'alphanumeric characters and underscores: %r' % name)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list