summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-10-16 19:18:30 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-10-16 19:18:30 (GMT)
commit050afbf214ae4066722c966ad653c199ad9c15ec (patch)
tree1ca13ac708b2a9f15b07b5d0359cf5569075cab6 /Lib
parent9fc1b96a19ef821174f5ce37d007b68a55b9ba67 (diff)
downloadcpython-050afbf214ae4066722c966ad653c199ad9c15ec.zip
cpython-050afbf214ae4066722c966ad653c199ad9c15ec.tar.gz
cpython-050afbf214ae4066722c966ad653c199ad9c15ec.tar.bz2
Improve error messages
Diffstat (limited to 'Lib')
-rw-r--r--Lib/collections.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 4515759..fbc00d1 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