@@ -1264,26 +1264,32 @@ _PyFunction_VerifyStateless(PyThreadState *tstate, PyObject *func)
1264
1264
}
1265
1265
// Disallow __defaults__.
1266
1266
PyObject * defaults = PyFunction_GET_DEFAULTS (func );
1267
- if (defaults != NULL && defaults != Py_None && PyDict_Size (defaults ) > 0 )
1268
- {
1269
- _PyErr_SetString (tstate , PyExc_ValueError , "defaults not supported" );
1270
- return -1 ;
1267
+ if (defaults != NULL ) {
1268
+ assert (PyTuple_Check (defaults )); // per PyFunction_New()
1269
+ if (PyTuple_GET_SIZE (defaults ) > 0 ) {
1270
+ _PyErr_SetString (tstate , PyExc_ValueError ,
1271
+ "defaults not supported" );
1272
+ return -1 ;
1273
+ }
1271
1274
}
1272
1275
// Disallow __kwdefaults__.
1273
1276
PyObject * kwdefaults = PyFunction_GET_KW_DEFAULTS (func );
1274
- if (kwdefaults != NULL && kwdefaults != Py_None
1275
- && PyDict_Size (kwdefaults ) > 0 )
1276
- {
1277
- _PyErr_SetString (tstate , PyExc_ValueError ,
1278
- "keyword defaults not supported" );
1279
- return -1 ;
1277
+ if (kwdefaults != NULL ) {
1278
+ assert (PyDict_Check (kwdefaults )); // per PyFunction_New()
1279
+ if (PyDict_Size (kwdefaults ) > 0 ) {
1280
+ _PyErr_SetString (tstate , PyExc_ValueError ,
1281
+ "keyword defaults not supported" );
1282
+ return -1 ;
1283
+ }
1280
1284
}
1281
1285
// Disallow __closure__.
1282
1286
PyObject * closure = PyFunction_GET_CLOSURE (func );
1283
- if (closure != NULL && closure != Py_None && PyTuple_GET_SIZE (closure ) > 0 )
1284
- {
1285
- _PyErr_SetString (tstate , PyExc_ValueError , "closures not supported" );
1286
- return -1 ;
1287
+ if (closure != NULL ) {
1288
+ assert (PyTuple_Check (closure )); // per PyFunction_New()
1289
+ if (PyTuple_GET_SIZE (closure ) > 0 ) {
1290
+ _PyErr_SetString (tstate , PyExc_ValueError , "closures not supported" );
1291
+ return -1 ;
1292
+ }
1287
1293
}
1288
1294
// Check the code.
1289
1295
PyCodeObject * co = (PyCodeObject * )PyFunction_GET_CODE (func );
0 commit comments