]> granicus.if.org Git - python/commitdiff
Replace assertion with straight error-checking.
authorRaymond Hettinger <python@rcn.com>
Mon, 21 May 2007 08:13:35 +0000 (08:13 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 21 May 2007 08:13:35 +0000 (08:13 +0000)
Lib/collections.py

index fa9a9a0f8a953a0b8991658b29f23e7d00609908..a2ce552ba2d8bb0ae9d171154508156e9f600324 100644 (file)
@@ -24,7 +24,8 @@ def NamedTuple(typename, s):
     """
 
     field_names = s.split()
-    assert ''.join(field_names).replace('_', '').isalpha()      # protect against exec attacks
+    if not ''.join([typename] + field_names).replace('_', '').isalpha():
+        raise ValueError('Type names and field names can only contain alphanumeric characters and underscores')
     argtxt = ', '.join(field_names)
     reprtxt = ', '.join('%s=%%r' % name for name in field_names)
     template = '''class %(typename)s(tuple):