Skip to content

Commit 88072b8

Browse files
committed
add support for non string keys to function's __dict__
1 parent 37b29a7 commit 88072b8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,5 @@ def bar():
441441

442442
bar.__dict__[1] = 1
443443
bar.a = 'a'
444-
assert bar.__dict__ == {1: 1, 'a': 'a'}
444+
assert 1 in bar.__dict__
445+
assert 'a' in bar.__dict__

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ protected boolean updateShape(DynamicObjectStorage storage, String name) {
489489
return readUncached(storage, name);
490490
}
491491

492+
@Specialization(guards = "!isJavaString(name)")
493+
protected boolean readUncached(PythonObjectHybridDictStorage storage, Object name) {
494+
return storage.hasKey(name, getEquivalence());
495+
}
496+
492497
@Specialization(guards = "!isJavaString(name)")
493498
@SuppressWarnings("unused")
494499
protected boolean readUncached(DynamicObjectStorage storage, Object name) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.graal.python.builtins.objects.PNone;
4747
import com.oracle.graal.python.builtins.objects.cell.PCell;
4848
import com.oracle.graal.python.builtins.objects.code.PCode;
49+
import com.oracle.graal.python.builtins.objects.dict.PDict;
4950
import com.oracle.graal.python.builtins.objects.module.PythonModule;
5051
import com.oracle.graal.python.builtins.objects.object.PythonObject;
5152
import com.oracle.graal.python.nodes.argument.CreateArgumentsNode;
@@ -234,7 +235,12 @@ Object builtinCode(PBuiltinFunction self, Object none) {
234235
static abstract class DictNode extends PythonUnaryBuiltinNode {
235236
@Specialization
236237
Object dict(PFunction self) {
237-
return factory().createMappingproxy(self);
238+
PDict dict = self.getDict();
239+
if (dict == null) {
240+
dict = factory().createDictFixedStorage(self);
241+
self.setDict(dict);
242+
}
243+
return dict;
238244
}
239245

240246
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)