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
8cefa4d3
Commit
8cefa4d3
authored
Mar 17, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #386 from undingen/virtualenv_fixes5
Make dict.fromkeys a class method
parents
58d1dc1f
50c6e493
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
12 deletions
+6
-12
src/runtime/dict.cpp
src/runtime/dict.cpp
+3
-7
test/tests/dict.py
test/tests/dict.py
+3
-5
No files found.
src/runtime/dict.cpp
View file @
8cefa4d3
...
...
@@ -411,11 +411,7 @@ Box* dictNonzero(BoxedDict* self) {
return
boxBool
(
self
->
d
.
size
());
}
Box
*
dictFromkeys
(
BoxedDict
*
self
,
Box
*
iterable
,
Box
*
default_value
)
{
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
raiseExcHelper
(
TypeError
,
"descriptor 'fromkeys' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
Box
*
dictFromkeys
(
Box
*
cls
,
Box
*
iterable
,
Box
*
default_value
)
{
auto
rtn
=
new
BoxedDict
();
for
(
Box
*
e
:
iterable
->
pyElements
())
{
dictSetitem
(
rtn
,
e
,
default_value
);
...
...
@@ -640,8 +636,6 @@ void setupDict() {
dict_cls
->
giveAttr
(
"copy"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictCopy
,
DICT
,
1
)));
dict_cls
->
giveAttr
(
"has_key"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictContains
,
BOXED_BOOL
,
2
)));
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
(
"iteritems"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictIterItems
,
typeFromClass
(
dict_iterator_cls
),
1
)));
...
...
@@ -656,6 +650,8 @@ void setupDict() {
dict_cls
->
giveAttr
(
"pop"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictPop
,
UNKNOWN
,
3
,
1
,
false
,
false
),
{
NULL
}));
dict_cls
->
giveAttr
(
"popitem"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictPopitem
,
BOXED_TUPLE
,
1
)));
auto
*
fromkeys_func
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictFromkeys
,
DICT
,
3
,
1
,
false
,
false
),
{
None
});
dict_cls
->
giveAttr
(
"fromkeys"
,
boxInstanceMethod
(
dict_cls
,
fromkeys_func
));
dict_cls
->
giveAttr
(
"viewkeys"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictViewKeys
,
UNKNOWN
,
1
)));
dict_cls
->
giveAttr
(
"viewvalues"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictViewValues
,
UNKNOWN
,
1
)));
...
...
test/tests/dict.py
View file @
8cefa4d3
...
...
@@ -127,11 +127,9 @@ 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
())
print
sorted
(
dict
.
fromkeys
([
1
,
2
]).
items
())
print
sorted
(
dict
.
fromkeys
([]).
items
())
print
sorted
(
dict
.
fromkeys
([
3
,
4
],
5
).
items
())
try
:
print
d
.
fromkeys
()
...
...
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