Skip to content

Commit e76ed35

Browse files
committed
[hotfix] fix __getitem__, __setitem__ and __delitem__ list fallback
PullRequest: graalpython-open/28
2 parents f5f665b + edbf71f commit e76ed35

File tree

1 file changed

+18
-9
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list

1 file changed

+18
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,12 @@ protected PNone doPListSlice(PList self, PSlice slice) {
227227
}
228228

229229
@SuppressWarnings("unused")
230-
@Specialization(guards = "!isValidIndexType(idx)")
231-
protected Object doGeneric(PList self, Object idx) {
232-
throw raise(PythonErrorType.TypeError, "list indices must be integers or slices, not %p", idx);
230+
@Fallback
231+
protected Object doGeneric(Object self, Object idx) {
232+
if (!isValidIndexType(idx)) {
233+
throw raise(TypeError, "list indices must be integers or slices, not %p", idx);
234+
}
235+
throw raise(TypeError, "descriptor '__delitem__' requires a 'list' object but received a '%p'", idx);
233236
}
234237

235238
protected boolean isValidIndexType(Object idx) {
@@ -310,9 +313,12 @@ protected Object doPListSlice(PList self, PSlice slice) {
310313
}
311314

312315
@SuppressWarnings("unused")
313-
@Specialization(guards = "!isValidIndexType(idx)")
314-
protected Object doGeneric(PList self, Object idx) {
315-
throw raise(PythonErrorType.TypeError, "list indices must be integers or slices, not %p", idx);
316+
@Fallback
317+
protected Object doGeneric(Object self, Object idx) {
318+
if (!isValidIndexType(idx)) {
319+
throw raise(TypeError, "list indices must be integers or slices, not %p", idx);
320+
}
321+
throw raise(TypeError, "descriptor '__getitem__' requires a 'list' object but received a '%p'", idx);
316322
}
317323

318324
protected boolean isValidIndexType(Object idx) {
@@ -389,9 +395,12 @@ public Object doPList(PList list, long idx, Object value,
389395
}
390396

391397
@SuppressWarnings("unused")
392-
@Specialization(guards = "!isValidIndexType(idx)")
393-
protected Object doGeneric(PList self, Object idx, Object value) {
394-
throw raise(PythonErrorType.TypeError, "list indices must be integers or slices, not %p", idx);
398+
@Fallback
399+
protected Object doGeneric(Object self, Object idx, Object value) {
400+
if (!isValidIndexType(idx)) {
401+
throw raise(TypeError, "list indices must be integers or slices, not %p", idx);
402+
}
403+
throw raise(TypeError, "descriptor '__setitem__' requires a 'list' object but received a '%p'", idx);
395404
}
396405

397406
protected boolean isValidIndexType(Object idx) {

0 commit comments

Comments
 (0)