Skip to content

Commit e3c83eb

Browse files
msimacektimfel
authored andcommitted
Fix error handling in PyObjectGetMethod
1 parent 6868658 commit e3c83eb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@
4040
*/
4141
package com.oracle.graal.python.lib;
4242

43+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
44+
4345
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4446
import com.oracle.graal.python.builtins.objects.PNone;
4547
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4648
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
4749
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
4850
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
4951
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
52+
import com.oracle.graal.python.nodes.ErrorMessages;
53+
import com.oracle.graal.python.nodes.PRaiseNode;
5054
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
5155
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
5256
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
@@ -108,6 +112,7 @@ static Object getFixedAttr(VirtualFrame frame, Object receiver, @SuppressWarning
108112
@Shared("lookupSet") @Cached(parameters = "Set") LookupCallableSlotInMRONode lookupSet,
109113
@Shared("callGet") @Cached CallTernaryMethodNode callGet,
110114
@Shared("readAttr") @Cached ReadAttributeFromObjectNode readAttr,
115+
@Shared("raiseNode") @Cached PRaiseNode raiseNode,
111116
@Cached BranchProfile hasDescr,
112117
@Cached BranchProfile returnDataDescr,
113118
@Cached BranchProfile returnAttr,
@@ -146,7 +151,7 @@ static Object getFixedAttr(VirtualFrame frame, Object receiver, @SuppressWarning
146151
returnBoundDescr.enter();
147152
return new BoundDescriptor(callGet.execute(frame, getMethod, descr, receiver, lazyClass));
148153
}
149-
return new BoundDescriptor(descr);
154+
throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
150155
}
151156

152157
// No explicit branch profiling when we're looking up multiple things
@@ -159,7 +164,8 @@ static Object getDynamicAttr(Frame frame, Object receiver, String name,
159164
@Shared("lookupGet") @Cached(parameters = "Get") LookupCallableSlotInMRONode lookupGet,
160165
@Shared("lookupSet") @Cached(parameters = "Set") LookupCallableSlotInMRONode lookupSet,
161166
@Shared("callGet") @Cached CallTernaryMethodNode callGet,
162-
@Shared("readAttr") @Cached ReadAttributeFromObjectNode readAttr) {
167+
@Shared("readAttr") @Cached ReadAttributeFromObjectNode readAttr,
168+
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
163169
boolean methodFound = false;
164170
Object descr = lookupNode.execute(lazyClass, name);
165171
Object getMethod = null;
@@ -185,6 +191,6 @@ static Object getDynamicAttr(Frame frame, Object receiver, String name,
185191
if (getMethod != null) {
186192
return new BoundDescriptor(callGet.execute(frame, getMethod, descr, receiver, lazyClass));
187193
}
188-
return new BoundDescriptor(descr);
194+
throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
189195
}
190196
}

0 commit comments

Comments
 (0)