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
a89e4d16
Commit
a89e4d16
authored
Nov 05, 2014
by
Leandro Lameiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dict.fromkeys + tests
parent
2c760930
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
src/runtime/dict.cpp
src/runtime/dict.cpp
+15
-0
test/tests/dict.py
test/tests/dict.py
+13
-0
No files found.
src/runtime/dict.cpp
View file @
a89e4d16
...
@@ -201,6 +201,19 @@ Box* dictNonzero(BoxedDict* self) {
...
@@ -201,6 +201,19 @@ Box* dictNonzero(BoxedDict* self) {
return
boxBool
(
self
->
d
.
size
());
return
boxBool
(
self
->
d
.
size
());
}
}
Box
*
dictFromkeys
(
BoxedDict
*
self
,
Box
*
iterable
,
Box
*
default_value
)
{
RELEASE_ASSERT
(
self
->
cls
==
dict_cls
,
""
);
auto
rtn
=
new
BoxedDict
();
for
(
Box
*
e
:
iterable
->
pyElements
())
{
dictSetitem
(
rtn
,
e
,
default_value
);
}
return
rtn
;
}
extern
"C"
Box
*
dictNew
(
Box
*
_cls
,
BoxedTuple
*
args
,
BoxedDict
*
kwargs
)
{
extern
"C"
Box
*
dictNew
(
Box
*
_cls
,
BoxedTuple
*
args
,
BoxedDict
*
kwargs
)
{
if
(
!
isSubclass
(
_cls
->
cls
,
type_cls
))
if
(
!
isSubclass
(
_cls
->
cls
,
type_cls
))
raiseExcHelper
(
TypeError
,
"dict.__new__(X): X is not a type object (%s)"
,
getTypeName
(
_cls
)
->
c_str
());
raiseExcHelper
(
TypeError
,
"dict.__new__(X): X is not a type object (%s)"
,
getTypeName
(
_cls
)
->
c_str
());
...
@@ -309,6 +322,8 @@ void setupDict() {
...
@@ -309,6 +322,8 @@ void setupDict() {
dict_cls
->
giveAttr
(
"clear"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictClear
,
NONE
,
1
)));
dict_cls
->
giveAttr
(
"clear"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictClear
,
NONE
,
1
)));
dict_cls
->
giveAttr
(
"copy"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictCopy
,
DICT
,
1
)));
dict_cls
->
giveAttr
(
"copy"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictCopy
,
DICT
,
1
)));
dict_cls
->
giveAttr
(
"fromkeys"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictFromkeys
,
DICT
,
3
,
1
,
false
,
false
),
{
None
}));
dict_cls
->
giveAttr
(
"items"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictItems
,
LIST
,
1
)));
dict_cls
->
giveAttr
(
"items"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictItems
,
LIST
,
1
)));
dict_cls
->
giveAttr
(
"iteritems"
,
dict_cls
->
giveAttr
(
"iteritems"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictIterItems
,
typeFromClass
(
dict_iterator_cls
),
1
)));
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictIterItems
,
typeFromClass
(
dict_iterator_cls
),
1
)));
...
...
test/tests/dict.py
View file @
a89e4d16
...
@@ -125,3 +125,16 @@ d = {}
...
@@ -125,3 +125,16 @@ d = {}
d
.
clear
()
d
.
clear
()
print
d
print
d
# fromkeys
d
=
{
1
:
2
,
3
:
4
}
print
sorted
(
d
.
fromkeys
([
1
,
2
]).
items
())
print
sorted
(
d
.
fromkeys
([]).
items
())
print
sorted
(
d
.
fromkeys
([
3
,
4
],
5
).
items
())
try
:
print
d
.
fromkeys
()
assert
0
except
TypeError
,
e
:
print
'ok'
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