@@ -114,8 +114,7 @@ private void arityCheck(Arity arity, int numOfArgs, int numOfKeywordsDeclared, i
114
114
if (numOfKeywordsGiven == 0 ) {
115
115
arityCheck (arity , numOfArgs );
116
116
} else if (!arity .takesKeywordArg () && numOfKeywordsGiven > 0 ) {
117
- Object [] args = {};
118
- throw raise (TypeError , arity .getFunctionName () + "() takes no keyword arguments" , args );
117
+ throw raise (TypeError , "%s() takes no keyword arguments" , arity .getFunctionName ());
119
118
} else {
120
119
for (int i = 0 ; i < numOfKeywordsGiven ; i ++) {
121
120
String keyword = keywords [i ];
@@ -136,37 +135,24 @@ private void checkKeyword(Arity arity, String keyword, int length) {
136
135
return ;
137
136
}
138
137
}
139
- Object [] args = {arity .getFunctionName (), keyword };
140
- throw raise (TypeError , "%s() got an unexpected keyword argument '%s'" , args );
138
+ throw raise (TypeError , "%s() got an unexpected keyword argument '%s'" , arity .getFunctionName (), keyword );
141
139
}
142
140
143
141
private void arityCheck (Arity arity , int numOfArgs ) {
144
- String argMessage ;
145
142
if (!arity .takesVarArgs () && arity .getMinNumOfArgs () == arity .getMaxNumOfArgs ()) {
146
143
if (numOfArgs != arity .getMinNumOfArgs ()) {
147
144
if (arity .getMinNumOfArgs () == 0 ) {
148
- argMessage = " no arguments" ;
145
+ throw raise ( TypeError , "%s() takes no arguments (%d given)" , arity . getFunctionName (), numOfArgs ) ;
149
146
} else if (arity .getMinNumOfArgs () == 1 ) {
150
- argMessage = " exactly one argument" ;
147
+ throw raise ( TypeError , "%s() takes exactly one argument (%d given)" , arity . getFunctionName (), numOfArgs ) ;
151
148
} else {
152
- argMessage = arity . getMinNumOfArgs () + " arguments" ;
149
+ throw raise ( TypeError , "%s () takes %d arguments (%d given)" , arity . getFunctionName (), arity . getMinNumOfArgs (), numOfArgs ) ;
153
150
}
154
- Object [] args = {arity .getFunctionName (), argMessage , numOfArgs };
155
- throw raise (TypeError , "%s() takes %s (%d given)" , args );
156
151
}
157
152
} else if (numOfArgs < arity .getMinNumOfArgs ()) {
158
- /**
159
- * For ex, iter(object[, sentinel]) takes at least 1 argument.
160
- */
161
- Object [] args = {arity .getFunctionName (), arity .getMinNumOfArgs (), numOfArgs };
162
- throw raise (TypeError , "%s() expected at least %d arguments (%d) given" , args );
153
+ throw raise (TypeError , "%s() expected at least %d arguments (%d) given" , arity .getFunctionName (), arity .getMinNumOfArgs (), numOfArgs );
163
154
} else if (!arity .takesVarArgs () && numOfArgs > arity .getMaxNumOfArgs ()) {
164
- /**
165
- * For ex, complex([real[, imag]]) takes at most 2 arguments.
166
- */
167
- argMessage = "at most " + arity .getMaxNumOfArgs () + " arguments" ;
168
- Object [] args = {arity .getFunctionName (), argMessage , numOfArgs };
169
- throw raise (TypeError , "%s() takes %s (%d given)" , args );
155
+ throw raise (TypeError , "%s() takes at most %d arguments (%d given)" , arity .getFunctionName (), arity .getMaxNumOfArgs (), numOfArgs );
170
156
}
171
157
}
172
158
}
0 commit comments