def _check_common(self, name, type_of_name):
# tests that are common to both field names and the type name
if len(name) == 0:
raise ValueError('{0} names cannot be zero '
'length: {1!r}'.format(type_of_name, name))
if _PY2:
if not all(c.isalnum() or c=='_' for c in name):
raise ValueError('{0} names can only contain '
'alphanumeric characters and underscores: '
'{1!r}'.format(type_of_name, name))
if name[0].isdigit():
raise ValueError('{0} names cannot start with a '
'number: {1!r}'.format(type_of_name, name))
else:
if not name.isidentifier():
raise ValueError('{0} names names must be valid '
'identifiers: {1!r}'.format(type_of_name, name))
if _iskeyword(name):
raise ValueError('{0} names cannot be a keyword: '
'{1!r}'.format(type_of_name, name))
评论列表
文章目录