Skip to content

Commit 8771a29

Browse files
committed
delete item from storage on popitem
1 parent b234688 commit 8771a29

File tree

1 file changed

+6
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict

1 file changed

+6
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.graal.python.builtins.objects.method.PMethod;
7070
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
7171
import com.oracle.graal.python.builtins.objects.str.PString;
72+
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
7273
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
7374
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
7475
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -228,8 +229,11 @@ public abstract static class PopItemNode extends PythonUnaryBuiltinNode {
228229
@Specialization(limit = "3")
229230
public Object popItem(PDict dict,
230231
@CachedLibrary("dict.getDictStorage()") HashingStorageLibrary lib) {
231-
for (DictEntry entry : lib.entries(dict.getDictStorage())) {
232-
return factory().createTuple(new Object[]{entry.getKey(), entry.getValue()});
232+
HashingStorage storage = dict.getDictStorage();
233+
for (DictEntry entry : lib.entries(storage)) {
234+
PTuple result = factory().createTuple(new Object[]{entry.getKey(), entry.getValue()});
235+
lib.delItem(storage, entry.getKey());
236+
return result;
233237
}
234238
throw raise(KeyError, ErrorMessages.IS_EMPTY, "popitem(): dictionary");
235239
}

0 commit comments

Comments
 (0)