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
d88d20e8
Commit
d88d20e8
authored
Oct 16, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #921 from Daetalus/test_set
Some stuff to enable "test_set"
parents
a419290b
7dc0be45
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
265 additions
and
61 deletions
+265
-61
from_cpython/Lib/test/test_set.py
from_cpython/Lib/test/test_set.py
+6
-4
src/runtime/dict.cpp
src/runtime/dict.cpp
+12
-4
src/runtime/set.cpp
src/runtime/set.cpp
+196
-53
test/tests/set.py
test/tests/set.py
+51
-0
No files found.
from_cpython/Lib/test/test_set.py
View file @
d88d20e8
# expected: fail
import
unittest
from
test
import
test_support
import
gc
...
...
@@ -339,7 +337,9 @@ class TestJointOps(unittest.TestCase):
obj
.
x
=
iter
(
container
)
del
obj
,
container
gc
.
collect
()
self
.
assertTrue
(
ref
()
is
None
,
"Cycle was not collected"
)
# Pyston change: because with conservative scanning
# it is hard to guarantee finalizer calls
# self.assertTrue(ref() is None, "Cycle was not collected")
class
TestSet
(
TestJointOps
):
thetype
=
set
...
...
@@ -560,7 +560,9 @@ class TestSet(TestJointOps):
p
=
weakref
.
proxy
(
s
)
self
.
assertEqual
(
str
(
p
),
str
(
s
))
s
=
None
self
.
assertRaises
(
ReferenceError
,
str
,
p
)
# Pyston change: because with conservative scanning
# it is hard to guarantee finalizer calls
# self.assertRaises(ReferenceError, str, p)
@
unittest
.
skipUnless
(
hasattr
(
set
,
"test_c_api"
),
'C API test only available in a debug build'
)
...
...
src/runtime/dict.cpp
View file @
d88d20e8
...
...
@@ -22,6 +22,7 @@
#include "runtime/ics.h"
#include "runtime/inline/list.h"
#include "runtime/objmodel.h"
#include "runtime/set.h"
#include "runtime/types.h"
#include "runtime/util.h"
...
...
@@ -510,11 +511,12 @@ Box* dictSetdefault(BoxedDict* self, Box* k, Box* v) {
raiseExcHelper
(
TypeError
,
"descriptor 'setdefault' requires a 'dict' object but received a '%s'"
,
getTypeName
(
self
));
auto
it
=
self
->
d
.
find
(
k
);
BoxAndHash
k_hash
(
k
);
auto
it
=
self
->
d
.
find
(
k_hash
);
if
(
it
!=
self
->
d
.
end
())
return
it
->
second
;
self
->
d
.
insert
(
std
::
make_pair
(
k
,
v
));
self
->
d
.
insert
(
std
::
make_pair
(
k
_hash
,
v
));
return
v
;
}
...
...
@@ -559,9 +561,15 @@ Box* dictNonzero(BoxedDict* self) {
Box
*
dictFromkeys
(
Box
*
cls
,
Box
*
iterable
,
Box
*
default_value
)
{
auto
rtn
=
new
BoxedDict
();
if
(
PyAnySet_Check
(
iterable
))
{
for
(
auto
&&
elt
:
((
BoxedSet
*
)
iterable
)
->
s
)
{
rtn
->
d
.
insert
(
std
::
make_pair
(
elt
,
default_value
));
}
}
else
{
for
(
Box
*
e
:
iterable
->
pyElements
())
{
dictSetitem
(
rtn
,
e
,
default_value
);
}
}
return
rtn
;
}
...
...
src/runtime/set.cpp
View file @
d88d20e8
This diff is collapsed.
Click to expand it.
test/tests/set.py
View file @
d88d20e8
...
...
@@ -199,3 +199,54 @@ try:
set
(
**
dict
(
a
=
1
))
except
TypeError
:
print
"TypeError"
class
MySet
(
set
):
def
__new__
(
cls
,
*
args
,
**
kwargs
):
return
set
.
__new__
(
cls
,
*
args
)
try
:
MySet
(
a
=
1
)
except
TypeError
as
e
:
print
(
e
.
message
)
class
SetSubclassWithKeywordArgs
(
set
):
def
__init__
(
self
,
iterable
=
[],
newarg
=
None
):
set
.
__init__
(
self
,
iterable
)
SetSubclassWithKeywordArgs
(
newarg
=
1
)
try
:
frozenset
(
a
=
1
)
except
TypeError
as
e
:
print
(
e
.
message
)
class
MyFrozenSet
(
frozenset
):
def
__new__
(
cls
,
*
args
,
**
kwargs
):
return
frozenset
.
__new__
(
cls
,
*
args
)
MyFrozenSet
(
a
=
1
)
class
FrozensetSubclassWithKeywordArgs
(
frozenset
):
def
__init__
(
self
,
iterable
=
[],
newarg
=
None
):
frozenset
.
__init__
(
self
,
iterable
)
FrozensetSubclassWithKeywordArgs
(
newarg
=
1
)
print
(
set
()
in
frozenset
([
frozenset
()]))
class
MySet
(
set
):
def
__hash__
(
self
):
print
(
"calling __hash__"
)
return
id
(
self
)
print
(
"Ready"
)
foo
=
MySet
()
a
=
set
()
a
.
add
(
foo
)
print
(
a
.
remove
(
foo
))
print
(
foo
in
set
())
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