summaryrefslogtreecommitdiff
path: root/Lib/collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-10-16 19:18:30 +0000
committerRaymond Hettinger <python@rcn.com>2007-10-16 19:18:30 +0000
commitf3d22cd9944eba42357e8d6a7686372b8b1ac2d5 (patch)
tree54255447e4d045e353ccc083ea5c986d99fdfd75 /Lib/collections.py
parent00ca7947a574d9be5c3763a9515c44ba4ca9f965 (diff)
downloadcpython-f3d22cd9944eba42357e8d6a7686372b8b1ac2d5.tar.gz
Improve error messages
Diffstat (limited to 'Lib/collections.py')
-rw-r--r--Lib/collections.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 4515759b78..fbc00d1fce 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -32,16 +32,17 @@ def named_tuple(typename, field_names, verbose=False):
if isinstance(field_names, basestring):
field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
field_names = tuple(field_names)
- if not ''.join((typename,) + field_names).replace('_', '').isalnum():
- raise ValueError('Type names and field names can only contain alphanumeric characters and underscores')
+ for name in (typename,) + field_names:
+ if not name.replace('_', '').isalnum():
+ raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
+ if name[0].isdigit():
+ raise ValueError('Type names and field names cannot start with a number: %r' % name)
seen_names = set()
for name in field_names:
if name.startswith('__') and name.endswith('__'):
- raise ValueError('Field names cannot start and end with double underscores: %s' % name)
- if name[:1].isdigit():
- raise ValueError('Field names cannot start with a number: %s' % name)
+ raise ValueError('Field names cannot start and end with double underscores: %r' % name)
if name in seen_names:
- raise ValueError('Encountered duplicate field name: %s' % name)
+ raise ValueError('Encountered duplicate field name: %r' % name)
seen_names.add(name)
# Create and fill-in the class template