@@ -2198,15 +2198,33 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
2198
2198
}
2199
2199
2200
2200
location loc = LOC (s );
2201
+
2202
+ if (typeparams ) {
2203
+ ADDOP (c , loc , PUSH_NULL );
2204
+ }
2205
+
2201
2206
funcflags = compiler_default_arguments (c , loc , args );
2202
2207
if (funcflags == -1 ) {
2203
2208
return ERROR ;
2204
2209
}
2205
2210
2206
2211
if (typeparams ) {
2207
- ADDOP (c , loc , PUSH_NULL );
2208
- RETURN_IF_ERROR (
2209
- compiler_enter_scope (c , name , scope_type , (void * )typeparams , firstlineno ));
2212
+ PyObject * typeparams_name = PyUnicode_FromFormat ("<generic parameters of %U>" , name );
2213
+ if (!typeparams_name ) {
2214
+ return ERROR ;
2215
+ }
2216
+ if (compiler_enter_scope (c , typeparams_name , scope_type ,
2217
+ (void * )typeparams , firstlineno ) == -1 ) {
2218
+ Py_DECREF (typeparams_name );
2219
+ return ERROR ;
2220
+ }
2221
+ Py_DECREF (typeparams_name );
2222
+ if ((funcflags & 0x01 ) || (funcflags & 0x02 )) {
2223
+ ADDOP_I (c , loc , LOAD_FAST , 0 );
2224
+ }
2225
+ if ((funcflags & 0x01 ) && (funcflags & 0x02 )) {
2226
+ ADDOP_I (c , loc , LOAD_FAST , 1 );
2227
+ }
2210
2228
RETURN_IF_ERROR (compiler_type_params (c , typeparams ));
2211
2229
}
2212
2230
@@ -2252,6 +2270,12 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
2252
2270
}
2253
2271
Py_DECREF (co );
2254
2272
if (typeparams ) {
2273
+ if (funcflags & 0x02 ) {
2274
+ c -> u -> u_argcount += 1 ;
2275
+ }
2276
+ if (funcflags & 0x01 ) {
2277
+ c -> u -> u_argcount += 1 ;
2278
+ }
2255
2279
PyCodeObject * co = assemble (c , 0 );
2256
2280
compiler_exit_scope (c );
2257
2281
if (co == NULL ) {
@@ -2262,7 +2286,16 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
2262
2286
return ERROR ;
2263
2287
}
2264
2288
Py_DECREF (co );
2265
- ADDOP_I (c , loc , CALL , 0 );
2289
+ int oparg = 0 ;
2290
+ if ((funcflags & 0x01 ) && (funcflags & 0x02 )) {
2291
+ ADDOP_I (c , loc , SWAP , 3 );
2292
+ oparg = 2 ;
2293
+ }
2294
+ else if ((funcflags & 0x01 ) || (funcflags & 0x02 )) {
2295
+ ADDOP_I (c , loc , SWAP , 2 );
2296
+ oparg = 1 ;
2297
+ }
2298
+ ADDOP_I (c , loc , CALL , oparg );
2266
2299
}
2267
2300
2268
2301
RETURN_IF_ERROR (compiler_apply_decorators (c , decos ));
@@ -7115,7 +7148,6 @@ compute_localsplus_info(struct compiler_unit *u, int nlocalsplus,
7115
7148
{
7116
7149
PyObject * k , * v ;
7117
7150
Py_ssize_t pos = 0 ;
7118
- // printf("compute_localsplus_info %d %s\n", nlocalsplus, PyUnicode_AsUTF8(u->u_name));
7119
7151
while (PyDict_Next (u -> u_varnames , & pos , & k , & v )) {
7120
7152
int offset = (int )PyLong_AS_LONG (v );
7121
7153
assert (offset >= 0 );
0 commit comments