mirror of
https://github.com/python/cpython.git
synced 2024-11-23 18:04:37 +08:00
merge
This commit is contained in:
commit
f2bbb651a8
@ -352,6 +352,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
|
|||||||
if isinstance(field_names, str):
|
if isinstance(field_names, str):
|
||||||
field_names = field_names.replace(',', ' ').split()
|
field_names = field_names.replace(',', ' ').split()
|
||||||
field_names = list(map(str, field_names))
|
field_names = list(map(str, field_names))
|
||||||
|
typename = str(typename)
|
||||||
if rename:
|
if rename:
|
||||||
seen = set()
|
seen = set()
|
||||||
for index, name in enumerate(field_names):
|
for index, name in enumerate(field_names):
|
||||||
@ -362,6 +363,8 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
|
|||||||
field_names[index] = '_%d' % index
|
field_names[index] = '_%d' % index
|
||||||
seen.add(name)
|
seen.add(name)
|
||||||
for name in [typename] + field_names:
|
for name in [typename] + field_names:
|
||||||
|
if type(name) != str:
|
||||||
|
raise TypeError('Type names and field names must be strings')
|
||||||
if not name.isidentifier():
|
if not name.isidentifier():
|
||||||
raise ValueError('Type names and field names must be valid '
|
raise ValueError('Type names and field names must be valid '
|
||||||
'identifiers: %r' % name)
|
'identifiers: %r' % name)
|
||||||
|
Loading…
Reference in New Issue
Block a user