Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4f4ba166
Commit
4f4ba166
authored
Mar 01, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17331: Use isidentifier() instead of isalnum() to check for valid identifiers.
parent
409f6630
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
9 deletions
+4
-9
Lib/collections/__init__.py
Lib/collections/__init__.py
+4
-9
No files found.
Lib/collections/__init__.py
View file @
4f4ba166
...
...
@@ -323,24 +323,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 underscore
s: %r'
%
name
)
if
not
name
.
isidentifier
(
):
raise
ValueError
(
'Type names and field names
must be valid
'
'
identifier
s: %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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment