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
6abd5698
Commit
6abd5698
authored
Jan 11, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic collections support
parent
7aaaf4bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
12 deletions
+51
-12
from_cpython/Lib/collections.py
from_cpython/Lib/collections.py
+28
-1
src/runtime/dict.cpp
src/runtime/dict.cpp
+1
-3
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+15
-6
test/tests/collections_test.py
test/tests/collections_test.py
+7
-2
No files found.
from_cpython/Lib/collections.py
View file @
6abd5698
...
...
@@ -124,7 +124,34 @@ class OrderedDict(dict):
for
k
in
self
:
yield
(
k
,
self
[
k
])
update
=
MutableMapping
.
update
# Pyston change: copied the code in from _abcoll rather than calling "update = MutableMapping.update"
def
update
(
*
args
,
**
kwds
):
''' D.update([E, ]**F) -> None. Update D from mapping/iterable E and F.
If E present and has a .keys() method, does: for k in E: D[k] = E[k]
If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
In either case, this is followed by: for k, v in F.items(): D[k] = v
'''
if
len
(
args
)
>
2
:
raise
TypeError
(
"update() takes at most 2 positional "
"arguments ({} given)"
.
format
(
len
(
args
)))
elif
not
args
:
raise
TypeError
(
"update() takes at least 1 argument (0 given)"
)
self
=
args
[
0
]
other
=
args
[
1
]
if
len
(
args
)
>=
2
else
()
# Pyston change: changed this from "Mapping" to "dict"
if
isinstance
(
other
,
dict
):
for
key
in
other
:
self
[
key
]
=
other
[
key
]
elif
hasattr
(
other
,
"keys"
):
for
key
in
other
.
keys
():
self
[
key
]
=
other
[
key
]
else
:
for
key
,
value
in
other
:
self
[
key
]
=
value
for
key
,
value
in
kwds
.
items
():
self
[
key
]
=
value
__update
=
update
# let subclasses override update without breaking __init__
...
...
src/runtime/dict.cpp
View file @
6abd5698
...
...
@@ -368,9 +368,7 @@ extern "C" Box* dictNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
raiseExcHelper
(
TypeError
,
"dict.__new__(%s): %s is not a subtype of dict"
,
getNameOfClass
(
cls
)
->
c_str
(),
getNameOfClass
(
cls
)
->
c_str
());
RELEASE_ASSERT
(
cls
==
dict_cls
,
""
);
return
new
BoxedDict
();
return
new
(
cls
)
BoxedDict
();
}
void
dictMerge
(
BoxedDict
*
self
,
Box
*
other
)
{
...
...
src/runtime/objmodel.cpp
View file @
6abd5698
...
...
@@ -1463,12 +1463,6 @@ extern "C" Box* getattr(Box* obj, const char* attr) {
#endif
}
if
(
strcmp
(
attr
,
"__dict__"
)
==
0
)
{
// TODO this is wrong, should be added at the class level as a getset
if
(
obj
->
cls
->
instancesHaveHCAttrs
())
return
makeAttrWrapper
(
obj
);
}
std
::
unique_ptr
<
Rewriter
>
rewriter
(
Rewriter
::
createRewriter
(
__builtin_extract_return_addr
(
__builtin_return_address
(
0
)),
2
,
"getattr"
));
...
...
@@ -1505,6 +1499,21 @@ extern "C" Box* getattr(Box* obj, const char* attr) {
if
(
val
)
{
return
val
;
}
if
(
attr
[
0
]
==
'_'
&&
attr
[
1
]
==
'_'
)
{
if
(
strcmp
(
attr
,
"__dict__"
)
==
0
)
{
// TODO this is wrong, should be added at the class level as a getset
if
(
obj
->
cls
->
instancesHaveHCAttrs
())
return
makeAttrWrapper
(
obj
);
}
// I'm not sure if there's more to it than this:
if
(
strcmp
(
attr
,
"__class__"
)
==
0
)
{
assert
(
obj
->
cls
!=
instance_cls
);
// I think in this case __class__ is supposed to be the classobj?
return
obj
->
cls
;
}
}
raiseAttributeError
(
obj
,
attr
);
}
...
...
test/tests/collections_test.py
View file @
6abd5698
# skip-if: True
# - wip
# allow-warning: converting unicode literal to str
import
collections
o
=
collections
.
OrderedDict
()
print
o
.
items
()
for
i
in
xrange
(
30
):
o
[(
i
**
2
)
^
0xace
]
=
i
print
o
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