Commit d88d20e8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #921 from Daetalus/test_set

Some stuff to enable "test_set"
parents a419290b 7dc0be45
# 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')
......
......@@ -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;
}
......
This diff is collapsed.
......@@ -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())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment