diff options
author | Raymond Hettinger <python@rcn.com> | 2013-03-02 07:51:26 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-03-02 07:51:26 (GMT) |
commit | a35e281200c16e3c725462463562c6928f38c54f (patch) | |
tree | caa72b1b29a94653968a2f3f9b48efa066439984 /Lib/collections/__init__.py | |
parent | 794568f0adc99d812d0d51ec700167a71a7e31df (diff) | |
parent | 4f4ba166771843a2fbadd4d62771967cfdbedb72 (diff) | |
download | cpython-a35e281200c16e3c725462463562c6928f38c54f.zip cpython-a35e281200c16e3c725462463562c6928f38c54f.tar.gz cpython-a35e281200c16e3c725462463562c6928f38c54f.tar.bz2 |
Merge
Diffstat (limited to 'Lib/collections/__init__.py')
-rw-r--r-- | Lib/collections/__init__.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 0612e1f..ca92c3c 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -322,24 +322,19 @@ def namedtuple(typename, field_names, verbose=False, rename=False): if rename: seen = set() for index, name in enumerate(field_names): - if (not all(c.isalnum() or c=='_' for c in name) + if (not name.isidentifier() or _iskeyword(name) - or not name - or name[0].isdigit() or name.startswith('_') or name in seen): field_names[index] = '_%d' % index seen.add(name) for name in [typename] + field_names: - 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) + if not name.isidentifier(): + raise ValueError('Type names and field names must be valid ' + 'identifiers: %r' % name) if _iskeyword(name): raise ValueError('Type names and field names cannot be a ' 'keyword: %r' % name) - if name[0].isdigit(): - raise ValueError('Type names and field names cannot start with ' - 'a number: %r' % name) seen = set() for name in field_names: if name.startswith('_') and not rename: |