Skip to content

Commit aa56fad

Browse files
committed
MethodBuiltins: fix get name node application
1 parent a80ef80 commit aa56fad

File tree

1 file changed

+10
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method

1 file changed

+10
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,20 @@ Object getName(VirtualFrame frame, PMethod method,
222222
public abstract static class MethodQualName extends PythonUnaryBuiltinNode {
223223
@Specialization(limit = "3")
224224
Object getQualName(VirtualFrame frame, PMethod method,
225-
@Cached("create(__QUALNAME__)") GetAttributeNode getQualNameAttrNode,
226225
@Cached("create(__NAME__)") GetAttributeNode getNameAttrNode,
226+
@Cached("create(__QUALNAME__)") GetAttributeNode getQualNameAttrNode,
227227
@Cached TypeNodes.IsTypeNode isTypeNode,
228228
@Cached CastToJavaStringNode castToJavaStringNode,
229229
@CachedLibrary("method.getSelf()") PythonObjectLibrary pol) {
230230
Object self = method.getSelf();
231-
String selfName = castToJavaStringNode.execute(getNameAttrNode.executeObject(frame, self));
232-
if (self instanceof PythonModule) {
233-
return selfName;
231+
String methodName;
232+
try {
233+
methodName = castToJavaStringNode.execute(getNameAttrNode.executeObject(frame, method));
234+
} catch (CannotCastException e) {
235+
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A, __NAME__, "unicode object");
236+
}
237+
if (self == null || self instanceof PythonModule) {
238+
return methodName;
234239
}
235240

236241
Object type = isTypeNode.execute(self) ? self : pol.getLazyPythonClass(self);
@@ -241,7 +246,7 @@ Object getQualName(VirtualFrame frame, PMethod method,
241246
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A, __QUALNAME__, "unicode object");
242247
}
243248

244-
return getQualNameGeneric(typeQualName, selfName);
249+
return getQualNameGeneric(typeQualName, methodName);
245250
}
246251

247252
@TruffleBoundary

0 commit comments

Comments
 (0)