Skip to content

Commit 95fe2fb

Browse files
author
Franziska Geiger
committed
[GR-15758] missing specialization for set delete
PullRequest: graalpython/513
2 parents f3c7a51 + 96d2c5c commit 95fe2fb

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
@@ -75,6 +75,7 @@
7575
import com.oracle.graal.python.builtins.objects.function.PKeyword;
7676
import com.oracle.graal.python.builtins.objects.ints.PInt;
7777
import com.oracle.graal.python.builtins.objects.object.PythonObject;
78+
import com.oracle.graal.python.builtins.objects.set.PSet;
7879
import com.oracle.graal.python.builtins.objects.str.LazyString;
7980
import com.oracle.graal.python.builtins.objects.str.PString;
8081
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
@@ -1496,11 +1497,21 @@ protected boolean doDynamicObjectString(@SuppressWarnings("unused") PDict contai
14961497
return storage.remove(key, DEFAULT_EQIVALENCE);
14971498
}
14981499

1500+
@Specialization
1501+
protected boolean doDynamicObjectString(@SuppressWarnings("unused") PSet container, DynamicObjectStorage storage, String key) {
1502+
return storage.remove(key, DEFAULT_EQIVALENCE);
1503+
}
1504+
14991505
@Specialization(guards = "wrappedString(key)")
15001506
protected boolean doDynamicObjectPString(@SuppressWarnings("unused") PDict container, DynamicObjectStorage storage, PString key) {
15011507
return storage.remove(key.getValue(), DEFAULT_EQIVALENCE);
15021508
}
15031509

1510+
@Specialization(guards = "wrappedString(key)")
1511+
protected boolean doDynamicObjectPString(@SuppressWarnings("unused") PSet container, DynamicObjectStorage storage, PString key) {
1512+
return storage.remove(key.getValue(), DEFAULT_EQIVALENCE);
1513+
}
1514+
15041515
@SuppressWarnings("unused")
15051516
@Specialization(guards = "!isJavaString(key)")
15061517
protected boolean doDynamicObject(PHashingCollection container, DynamicObjectStorage storage, Object key) {

0 commit comments

Comments
 (0)