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
767debb6
Commit
767debb6
authored
May 21, 2007
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow all alphanumeric and underscores in type and field names.
parent
0d6a8ccf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
1 deletion
+4
-1
Lib/collections.py
Lib/collections.py
+1
-1
Lib/test/test_collections.py
Lib/test/test_collections.py
+3
-0
No files found.
Lib/collections.py
View file @
767debb6
...
...
@@ -24,7 +24,7 @@ def NamedTuple(typename, s):
"""
field_names
=
s
.
split
()
if
not
''
.
join
([
typename
]
+
field_names
).
replace
(
'_'
,
''
).
isal
pha
():
if
not
''
.
join
([
typename
]
+
field_names
).
replace
(
'_'
,
''
).
isal
num
():
raise
ValueError
(
'Type names and field names can only contain alphanumeric characters and underscores'
)
argtxt
=
', '
.
join
(
field_names
)
reprtxt
=
', '
.
join
(
'%s=%%r'
%
name
for
name
in
field_names
)
...
...
Lib/test/test_collections.py
View file @
767debb6
...
...
@@ -11,6 +11,9 @@ class TestNamedTuple(unittest.TestCase):
self
.
assertEqual
(
Point
.
__slots__
,
())
self
.
assertEqual
(
Point
.
__module__
,
__name__
)
self
.
assertEqual
(
Point
.
__getitem__
,
tuple
.
__getitem__
)
self
.
assertRaises
(
ValueError
,
NamedTuple
,
'abc%'
,
'def ghi'
)
self
.
assertRaises
(
ValueError
,
NamedTuple
,
'abc'
,
'def g%hi'
)
NamedTuple
(
'Point0'
,
'x1 y2'
)
# Verify that numbers are allowed in names
def
test_instance
(
self
):
Point
=
NamedTuple
(
'Point'
,
'x y'
)
...
...
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