@@ -521,18 +521,17 @@ Object[] applyUncached(Object callee, Signature calleeSignature, Object[] argume
521
521
@ Cached PRaiseNode raise ,
522
522
@ Exclusive @ Cached SearchNamedParameterNode searchParamNode ,
523
523
@ Exclusive @ Cached SearchNamedParameterNode searchKwNode ) {
524
- boolean takesVarKwds = calleeSignature .takesVarKeywordArgs ();
525
524
String [] parameters = calleeSignature .getParameterIds ();
526
525
int positionalParamNum = parameters .length ;
527
526
String [] kwNames = calleeSignature .getKeywordNames ();
528
- PKeyword [] unusedKeywords = new PKeyword [keywords .length ];
527
+ int kwLen = keywords .length ;
528
+ PKeyword [] unusedKeywords = calleeSignature .takesVarKeywordArgs () ? new PKeyword [kwLen ] : null ;
529
529
// same as above
530
530
int k = 0 ;
531
531
int additionalKwds = 0 ;
532
- int positionalOnlyArgIndex = calleeSignature .getPositionalOnlyArgIndex ();
533
-
534
532
String lastWrongKeyword = null ;
535
- for (int i = 0 ; i < keywords .length ; i ++) {
533
+ int positionalOnlyArgIndex = calleeSignature .getPositionalOnlyArgIndex ();
534
+ for (int i = 0 ; i < kwLen ; i ++) {
536
535
PKeyword kwArg = keywords [i ];
537
536
String name = kwArg .getName ();
538
537
int kwIdx = searchParamNode .execute (parameters , name );
@@ -545,13 +544,18 @@ Object[] applyUncached(Object callee, Signature calleeSignature, Object[] argume
545
544
546
545
if (kwIdx != -1 ) {
547
546
if (positionalOnlyArgIndex > -1 && kwIdx < positionalOnlyArgIndex ) {
548
- throw raise .raise (PythonBuiltinClassType .TypeError , ErrorMessages .GOT_SOME_POS_ONLY_ARGS_PASSED_AS_KEYWORD , CreateArgumentsNode .getName (callee ), name );
549
- }
550
- if (PArguments .getArgument (arguments , kwIdx ) != null ) {
551
- throw raise .raise (PythonBuiltinClassType .TypeError , ErrorMessages .GOT_MULTIPLE_VALUES_FOR_ARG , CreateArgumentsNode .getName (callee ), name );
547
+ if (unusedKeywords != null ) {
548
+ unusedKeywords [k ++] = kwArg ;
549
+ } else {
550
+ throw raise .raise (PythonBuiltinClassType .TypeError , ErrorMessages .GOT_SOME_POS_ONLY_ARGS_PASSED_AS_KEYWORD , CreateArgumentsNode .getName (callee ), name );
551
+ }
552
+ } else {
553
+ if (PArguments .getArgument (arguments , kwIdx ) != null ) {
554
+ throw raise .raise (PythonBuiltinClassType .TypeError , ErrorMessages .GOT_MULTIPLE_VALUES_FOR_ARG , CreateArgumentsNode .getName (callee ), name );
555
+ }
556
+ PArguments .setArgument (arguments , kwIdx , kwArg .getValue ());
552
557
}
553
- PArguments .setArgument (arguments , kwIdx , kwArg .getValue ());
554
- } else if (takesVarKwds ) {
558
+ } else if (unusedKeywords != null ) {
555
559
unusedKeywords [k ++] = kwArg ;
556
560
} else {
557
561
additionalKwds ++;
0 commit comments