[Python-checkins] cpython (3.3): Issue #17331: Use isidentifier() instead of isalnum() to check for valid

raymond.hettinger python-checkins at python.org
Sat Mar 2 08:51:55 CET 2013


http://hg.python.org/cpython/rev/80bcc98bf939
changeset: 82452:80bcc98bf939
branch: 3.3
parent: 82450:e9732c25a018
user: Raymond Hettinger <python at rcn.com>
date: Fri Mar 01 23:43:48 2013 -0800
summary:
 Issue #17331: Use isidentifier() instead of isalnum() to check for valid identifiers.
files:
 Lib/collections/__init__.py | 13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -323,24 +323,19 @@
 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:
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /