Skip to content

Commit 49d9056

Browse files
committed
Raise exceptions from as* messages on PythonBuiltinClassType
1 parent c384094 commit 49d9056

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
3434
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
3535
import com.oracle.graal.python.nodes.BuiltinNames;
36+
import com.oracle.graal.python.nodes.ErrorMessages;
37+
import com.oracle.graal.python.nodes.PRaiseNode;
3638
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
3739
import com.oracle.graal.python.runtime.PythonContext;
3840
import com.oracle.truffle.api.CompilerAsserts;
@@ -525,52 +527,24 @@ static long hashWithState(PythonBuiltinClassType type, ThreadState state,
525527
}
526528

527529
@ExportMessage
528-
static Object asIndexWithState(PythonBuiltinClassType type, ThreadState state,
529-
@CachedContext(PythonLanguage.class) PythonContext context,
530-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
531-
return lib.asIndexWithState(context.getCore().lookupType(type), state);
532-
}
533-
534-
@ExportMessage
535-
static String asPathWithState(PythonBuiltinClassType type, ThreadState state,
536-
@CachedContext(PythonLanguage.class) PythonContext context,
537-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
538-
return lib.asPathWithState(context.getCore().lookupType(type), state);
539-
}
540-
541-
@ExportMessage
542-
static int asFileDescriptorWithState(PythonBuiltinClassType type, ThreadState state,
543-
@CachedContext(PythonLanguage.class) PythonContext context,
544-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
545-
return lib.asFileDescriptorWithState(context.getCore().lookupType(type), state);
546-
}
547-
548-
@ExportMessage
530+
@SuppressWarnings("unused")
549531
static double asJavaDoubleWithState(PythonBuiltinClassType type, ThreadState state,
550-
@CachedContext(PythonLanguage.class) PythonContext context,
551-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
552-
return lib.asJavaDoubleWithState(context.getCore().lookupType(type), state);
532+
@Cached PRaiseNode raiseNode) {
533+
throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_REAL_NUMBER, type);
553534
}
554535

555536
@ExportMessage
537+
@SuppressWarnings("unused")
556538
static Object asPIntWithState(PythonBuiltinClassType type, ThreadState state,
557-
@CachedContext(PythonLanguage.class) PythonContext context,
558-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
559-
return lib.asPIntWithState(context.getCore().lookupType(type), state);
539+
@Cached PRaiseNode raiseNode) {
540+
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, type);
560541
}
561542

562543
@ExportMessage
544+
@SuppressWarnings("unused")
563545
static long asJavaLongWithState(PythonBuiltinClassType type, ThreadState state,
564-
@CachedContext(PythonLanguage.class) PythonContext context,
565-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
566-
return lib.asJavaLongWithState(context.getCore().lookupType(type), state);
567-
}
568-
569-
@ExportMessage
570-
static int asSizeWithState(PythonBuiltinClassType type, Object errorType, ThreadState state,
571-
@CachedContext(PythonLanguage.class) PythonContext context,
572-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
573-
return lib.asSizeWithState(context.getCore().lookupType(type), errorType, state);
546+
@Cached PRaiseNode raiseNode) {
547+
throw raiseNode.raise(TypeError, ErrorMessages.MUST_BE_NUMERIC, type);
574548
}
575549

576550
@ExportMessage

0 commit comments

Comments
 (0)