Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
7ea200d7
Commit
7ea200d7
authored
Jan 06, 2015
by
asaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add type check in viewkeys / viewvalues / viewitems method on dict
parent
ca306a4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
src/runtime/dict.cpp
src/runtime/dict.cpp
+12
-0
test/tests/dict.py
test/tests/dict.py
+6
-0
No files found.
src/runtime/dict.cpp
View file @
7ea200d7
...
...
@@ -91,16 +91,28 @@ Box* dictKeys(BoxedDict* self) {
}
Box
*
dictViewKeys
(
BoxedDict
*
self
)
{
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewkeys' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
)
->
c_str
());
}
BoxedDictView
*
rtn
=
new
BoxedDictView
(
self
,
dict_keys_cls
);
return
rtn
;
}
Box
*
dictViewValues
(
BoxedDict
*
self
)
{
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewvalues' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
)
->
c_str
());
}
BoxedDictView
*
rtn
=
new
BoxedDictView
(
self
,
dict_values_cls
);
return
rtn
;
}
Box
*
dictViewItems
(
BoxedDict
*
self
)
{
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewitems' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
)
->
c_str
());
}
BoxedDictView
*
rtn
=
new
BoxedDictView
(
self
,
dict_items_cls
);
return
rtn
;
}
...
...
test/tests/dict.py
View file @
7ea200d7
...
...
@@ -197,13 +197,19 @@ print sorted(d.items())
# viewkeys / viewvalues / viewitems
d
=
{}
keys
=
d
.
keys
()
viewkeys
=
d
.
viewkeys
()
print
list
(
d
.
viewkeys
())
print
list
(
d
.
viewvalues
())
print
list
(
d
.
viewitems
())
print
'keys of d: '
,
keys
print
'viewkeys of d: '
,
list
(
viewkeys
)
d
[
'a'
]
=
1
print
list
(
d
.
viewkeys
())
print
list
(
d
.
viewvalues
())
print
list
(
d
.
viewitems
())
print
'keys of d: '
,
keys
print
'viewkeys of d: '
,
list
(
viewkeys
)
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