Skip to content

Commit b810758

Browse files
committed
no arg set.__init__() should clear data
1 parent 0a38ee8 commit b810758

File tree

2 files changed

+12
-3
lines changed
  • graalpython
    • com.oracle.graal.python.test/src/tests
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set

2 files changed

+12
-3
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_set.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
# ankitv 10/10/13
4141
# Iterating by Sequence Index
4242

43+
from collections.abc import MutableSet
4344

4445
def assert_raises(err, fn, *args, **kwargs):
4546
raised = False
@@ -315,6 +316,12 @@ def test_same_id():
315316
empty_ids = set([id(frozenset()) for i in range(100)])
316317
assert len(empty_ids) == 1
317318

319+
def test_init():
320+
s = {1, 2, 3}
321+
s.__init__({4})
322+
assert s == {4}
323+
s.__init__()
324+
assert s == set()
318325

319326
def test_rich_compare():
320327
class TestRichSetCompare:

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
8686
@ImportStatic(PGuards.class)
8787
public abstract static class InitNode extends PythonBuiltinNode {
8888

89-
@Specialization(guards = "isNoValue(iterable)")
90-
@SuppressWarnings("unused")
91-
static PNone doNoValue(VirtualFrame frame, PSet self, PNone iterable) {
89+
@Specialization(guards = "isNoValue(iterable)", limit = "1")
90+
static PNone doNoValue(PSet self, @SuppressWarnings("unused") PNone iterable,
91+
@CachedLibrary("self.getDictStorage()") HashingStorageLibrary lib) {
92+
HashingStorage newStorage = lib.clear(self.getDictStorage());
93+
self.setDictStorage(newStorage);
9294
return PNone.NONE;
9395
}
9496

0 commit comments

Comments
 (0)