Skip to content

Commit 715b2cd

Browse files
author
Franziska Geiger
committed
add delete set item unittest
- add missing specialization for set delete
1 parent c031021 commit 715b2cd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,15 @@ def test_pop():
272272
except BaseException as e:
273273
assert type(e) == KeyError, "expected KeyError, got %s" % type(e)
274274

275+
276+
def test_set_delete():
277+
s = {1, 2, 3}
278+
assert s == {1, 2, 3}
279+
s.discard(3)
280+
assert s == {1, 2}
281+
282+
# string keys
283+
s = {'a', 'b', 'c'}
284+
assert s == {'a', 'b', 'c'}
285+
s.discard('c')
286+
assert s == {'a', 'b'}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.oracle.graal.python.builtins.objects.function.PKeyword;
7575
import com.oracle.graal.python.builtins.objects.ints.PInt;
7676
import com.oracle.graal.python.builtins.objects.object.PythonObject;
77+
import com.oracle.graal.python.builtins.objects.set.PSet;
7778
import com.oracle.graal.python.builtins.objects.str.PString;
7879
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
7980
import com.oracle.graal.python.nodes.PGuards;
@@ -1320,11 +1321,21 @@ protected boolean doDynamicObjectString(@SuppressWarnings("unused") PDict contai
13201321
return storage.remove(key, DEFAULT_EQIVALENCE);
13211322
}
13221323

1324+
@Specialization
1325+
protected boolean doDynamicObjectString(@SuppressWarnings("unused") PSet container, DynamicObjectStorage storage, String key) {
1326+
return storage.remove(key, DEFAULT_EQIVALENCE);
1327+
}
1328+
13231329
@Specialization(guards = "wrappedString(key)")
13241330
protected boolean doDynamicObjectPString(@SuppressWarnings("unused") PDict container, DynamicObjectStorage storage, PString key) {
13251331
return storage.remove(key.getValue(), DEFAULT_EQIVALENCE);
13261332
}
13271333

1334+
@Specialization(guards = "wrappedString(key)")
1335+
protected boolean doDynamicObjectPString(@SuppressWarnings("unused") PSet container, DynamicObjectStorage storage, PString key) {
1336+
return storage.remove(key.getValue(), DEFAULT_EQIVALENCE);
1337+
}
1338+
13281339
@SuppressWarnings("unused")
13291340
@Specialization(guards = "!isJavaString(key)")
13301341
protected boolean doDynamicObject(PHashingCollection container, DynamicObjectStorage storage, Object key) {

0 commit comments

Comments
 (0)