Skip to content

Commit a43e8fc

Browse files
committed
Fix: raise TypeError for missing arguments
1 parent f5515e6 commit a43e8fc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtParseArgumentsNode.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,19 @@ abstract static class GetArgNode extends Node {
10231023
static Object doNoKeywords(ParserState state, Object kwds, Object kwdnames, boolean keywordsOnly,
10241024
@Shared("lenNode") @Cached SequenceNodes.LenNode lenNode,
10251025
@Shared("getSequenceStorageNode") @Cached GetSequenceStorageNode getSequenceStorageNode,
1026-
@Shared("getItemNode") @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode) {
1026+
@Shared("getItemNode") @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
1027+
@Shared("raiseNode") @Cached PRaiseNativeNode raiseNode) {
10271028

10281029
Object out = null;
10291030
assert !keywordsOnly;
10301031
int l = lenNode.execute(state.v.argv);
10311032
if (state.v.argnum < l) {
10321033
out = getItemNode.execute(getSequenceStorageNode.execute(state.v.argv), state.v.argnum);
10331034
}
1035+
if (out == null && !state.restOptional) {
1036+
raiseNode.raiseIntWithoutFrame(0, TypeError, "%s missing required argument (pos %d)", state.funName, state.v.argnum);
1037+
throw ParseArgumentsException.raise();
1038+
}
10341039
state.v.argnum++;
10351040
return out;
10361041
}
@@ -1043,7 +1048,8 @@ static Object doGeneric(ParserState state, Object kwds, Object kwdnames, boolean
10431048
@Cached HashingCollectionNodes.GetDictStorageNode getDictStorageNode,
10441049
@CachedLibrary(limit = "1") InteropLibrary kwdnamesLib,
10451050
@CachedLibrary(limit = "1") HashingStorageLibrary lib,
1046-
@Cached PCallCExtFunction callCStringToString) throws InteropException {
1051+
@Cached PCallCExtFunction callCStringToString,
1052+
@Shared("raiseNode") @Cached PRaiseNativeNode raiseNode) throws InteropException {
10471053

10481054
Object out = null;
10491055
if (!keywordsOnly) {
@@ -1064,6 +1070,10 @@ static Object doGeneric(ParserState state, Object kwds, Object kwdnames, boolean
10641070
out = lib.getItem(getDictStorageNode.execute((PDict) kwds), kwdname);
10651071
}
10661072
}
1073+
if (out == null && !state.restOptional) {
1074+
raiseNode.raiseIntWithoutFrame(0, TypeError, "%s missing required argument (pos %d)", state.funName, state.v.argnum);
1075+
throw ParseArgumentsException.raise();
1076+
}
10671077
state.v.argnum++;
10681078
return out;
10691079
}

0 commit comments

Comments
 (0)