Skip to content

Commit 6ad022a

Browse files
committed
[GR-13548] Allow 'NotImplemented' to be returned in a subscript operation.
PullRequest: graalpython/381
2 parents 3313f49 + 178d230 commit 6ad022a

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -219,6 +219,10 @@ def __index__(self):
219219
return 1.0;
220220

221221
raiseTypeError(t, IndexF())
222+
223+
t = (NotImplemented,)
224+
self.assertEqual(t[0], NotImplemented)
225+
222226

223227
# Tests for Truffle specializations
224228
def test_lying_tuple(self):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallBinaryNode.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,14 @@ boolean callBoolean(double left, double right,
270270
Object callObject(Object left, Object right,
271271
@Cached("create(name)") LookupInheritedAttributeNode getattr) {
272272
Object leftCallable = getattr.execute(left);
273-
Object result;
274273
if (leftCallable == PNone.NO_VALUE) {
275-
result = PNotImplemented.NOT_IMPLEMENTED;
276-
} else {
277-
result = ensureDispatch().executeObject(leftCallable, left, right);
278-
}
279-
if (handlerFactory != null && result == PNotImplemented.NOT_IMPLEMENTED) {
280-
if (handler == null) {
281-
CompilerDirectives.transferToInterpreterAndInvalidate();
282-
handler = insert(handlerFactory.get());
274+
if (handlerFactory != null) {
275+
return runErrorHandler(left, right);
276+
} else {
277+
return PNotImplemented.NOT_IMPLEMENTED;
283278
}
284-
return handler.execute(left, right);
285279
}
286-
return result;
280+
return ensureDispatch().executeObject(leftCallable, left, right);
287281
}
288282

289283
@Specialization(guards = "isReversible()")
@@ -319,12 +313,16 @@ Object callObject(Object left, Object right,
319313
result = ensureReverseDispatch().executeObject(rightCallable, right, left);
320314
}
321315
if (handlerFactory != null && result == PNotImplemented.NOT_IMPLEMENTED) {
322-
if (handler == null) {
323-
CompilerDirectives.transferToInterpreterAndInvalidate();
324-
handler = insert(handlerFactory.get());
325-
}
326-
return handler.execute(left, right);
316+
return runErrorHandler(left, right);
327317
}
328318
return result;
329319
}
320+
321+
private Object runErrorHandler(Object left, Object right) {
322+
if (handler == null) {
323+
CompilerDirectives.transferToInterpreterAndInvalidate();
324+
handler = insert(handlerFactory.get());
325+
}
326+
return handler.execute(left, right);
327+
}
330328
}

0 commit comments

Comments
 (0)