Skip to content

Commit b7226e4

Browse files
committed
Don't report generic iterables as arrays
Fixes #130 Fixes #141
1 parent 3944116 commit b7226e4

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,13 @@ public Object readMember(String key,
275275
@ExportMessage
276276
public boolean hasArrayElements(
277277
@CachedLibrary("this") PythonObjectLibrary dataModelLibrary) {
278-
return (dataModelLibrary.isSequence(this) || dataModelLibrary.isIterable(this)) && !dataModelLibrary.isMapping(this);
278+
return dataModelLibrary.isSequence(this) && !dataModelLibrary.isMapping(this);
279279
}
280280

281281
@ExportMessage
282282
public Object readArrayElement(long key,
283283
@CachedLibrary("this") PythonObjectLibrary dataModelLibrary,
284284
@Shared("getItemNode") @Cached PInteropSubscriptNode getItemNode,
285-
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupIterNode,
286-
@Exclusive @Cached LookupInheritedAttributeNode.Dynamic lookupNextNode,
287-
@Exclusive @Cached CallNode callIterNode,
288-
@Exclusive @Cached CallNode callNextNode,
289285
@Shared("toForeign") @Cached PTypeToForeignNode toForeign) throws UnsupportedMessageException, InvalidArrayIndexException {
290286
if (dataModelLibrary.isSequence(this)) {
291287
try {
@@ -301,21 +297,6 @@ public Object readArrayElement(long key,
301297
}
302298
}
303299

304-
if (dataModelLibrary.isIterable(this)) {
305-
Object attrIter = lookupIterNode.execute(this, SpecialMethodNames.__ITER__);
306-
Object iter = callIterNode.execute(null, attrIter, this);
307-
if (iter != this) {
308-
// there is a separate iterator for this object, should be safe to consume
309-
Object result = iterateToKey(lookupNextNode, callNextNode, iter, key);
310-
if (result != PNone.NO_VALUE) {
311-
return result;
312-
}
313-
// TODO(fa) refine exception handling
314-
// it's an iterable, so we assume the index is wrong
315-
throw InvalidArrayIndexException.create(key);
316-
}
317-
}
318-
319300
throw UnsupportedMessageException.create();
320301
}
321302

@@ -353,15 +334,6 @@ public void removeArrayElement(long key,
353334
}
354335
}
355336

356-
private static Object iterateToKey(LookupInheritedAttributeNode.Dynamic lookupNextNode, CallNode callNextNode, Object iter, long key) {
357-
Object value = PNone.NO_VALUE;
358-
for (long i = 0; i <= key; i++) {
359-
Object attrNext = lookupNextNode.execute(iter, SpecialMethodNames.__NEXT__);
360-
value = callNextNode.execute(null, attrNext, iter);
361-
}
362-
return value;
363-
}
364-
365337
@ExportMessage
366338
public long getArraySize(@CachedLibrary("this") PythonObjectLibrary lib) throws UnsupportedMessageException {
367339
// since a call to this method must be preceded by a call to 'hasArrayElements', we just

0 commit comments

Comments
 (0)