@@ -225,6 +225,7 @@ public Object execute(Object object, Object key) {
225
225
}
226
226
227
227
private static final class KeysNode extends Node {
228
+ private static final String PRIVATE_PREFIX = "__" ;
228
229
@ Child private LookupAndCallUnaryNode keysNode = LookupAndCallUnaryNode .create (SpecialMethodNames .KEYS );
229
230
@ Child private CastToListNode castToList = CastToListNode .create ();
230
231
@ Child private GetClassNode getClass = GetClassNode .create ();
@@ -243,10 +244,10 @@ public Object execute(Object obj, boolean includeInternal) {
243
244
HashSet <String > keys = new HashSet <>();
244
245
PythonClass klass = getClass .execute (object );
245
246
for (PythonObject o : klass .getMethodResolutionOrder ()) {
246
- addKeysFromObject (keys , o );
247
+ addKeysFromObject (keys , o , includeInternal );
247
248
}
248
249
if (object instanceof PythonObject ) {
249
- addKeysFromObject (keys , (PythonObject ) object );
250
+ addKeysFromObject (keys , (PythonObject ) object , includeInternal );
250
251
}
251
252
if (includeInternal ) {
252
253
// we use the internal flag to also return dictionary keys for mappings
@@ -272,12 +273,18 @@ public Object execute(Object obj, boolean includeInternal) {
272
273
return factory .createTuple (keys .toArray (new String [keys .size ()]));
273
274
}
274
275
275
- private static void addKeysFromObject (HashSet <String > keys , PythonObject o ) {
276
+ private static void addKeysFromObject (HashSet <String > keys , PythonObject o , boolean includeInternal ) {
276
277
for (Object k : o .getStorage ().getShape ().getKeys ()) {
278
+ String strKey ;
277
279
if (k instanceof String ) {
278
- keys . add (( String ) k ) ;
280
+ strKey = ( String ) k ;
279
281
} else if (k instanceof PString ) {
280
- keys .add (((PString ) k ).getValue ());
282
+ strKey = ((PString ) k ).getValue ();
283
+ } else {
284
+ continue ;
285
+ }
286
+ if (includeInternal || !strKey .startsWith (PRIVATE_PREFIX )) {
287
+ keys .add (strKey );
281
288
}
282
289
}
283
290
}
@@ -622,9 +629,15 @@ abstract static class PKeyInfoNode extends Node {
622
629
@ Child private LookupInheritedAttributeNode getSetNode ;
623
630
@ Child private LookupInheritedAttributeNode getDeleteNode ;
624
631
@ Child private GetClassNode getClassNode = GetClassNode .create ();
625
- @ Child IsImmutable isImmutable = new IsImmutable ();
632
+ @ Child private IsImmutable isImmutable = new IsImmutable ();
633
+ @ Child private KeyForItemAccess itemKey = new KeyForItemAccess ();
626
634
627
635
public int access (Object object , Object fieldName ) {
636
+ String itemFieldName = itemKey .execute (fieldName );
637
+ if (itemFieldName != null ) {
638
+ return KeyInfo .READABLE | KeyInfo .MODIFIABLE | KeyInfo .REMOVABLE | KeyInfo .REMOVABLE ;
639
+ }
640
+
628
641
Object owner = object ;
629
642
int info = KeyInfo .NONE ;
630
643
Object attr = PNone .NO_VALUE ;
0 commit comments