@@ -119,6 +119,7 @@ _PyFunction_FromConstructor(PyFrameConstructor *constr)
119119 op -> func_defaults = Py_XNewRef (constr -> fc_defaults );
120120 op -> func_kwdefaults = Py_XNewRef (constr -> fc_kwdefaults );
121121 op -> func_closure = Py_XNewRef (constr -> fc_closure );
122+ op -> func_class_dict = NULL ;
122123 op -> func_doc = Py_NewRef (Py_None );
123124 op -> func_dict = NULL ;
124125 op -> func_weakreflist = NULL ;
@@ -204,6 +205,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
204205 op -> func_module = module ;
205206 op -> func_annotations = NULL ;
206207 op -> func_typeparams = NULL ;
208+ op -> func_class_dict = NULL ;
207209 op -> vectorcall = _PyFunction_Vectorcall ;
208210 op -> func_version = 0 ;
209211 _PyObject_GC_TRACK (op );
@@ -264,6 +266,16 @@ PyFunction_GetGlobals(PyObject *op)
264266 return ((PyFunctionObject * ) op ) -> func_globals ;
265267}
266268
269+ PyObject *
270+ PyFunction_GetClassDict (PyObject * op )
271+ {
272+ if (!PyFunction_Check (op )) {
273+ PyErr_BadInternalCall ();
274+ return NULL ;
275+ }
276+ return ((PyFunctionObject * ) op ) -> func_class_dict ;
277+ }
278+
267279PyObject *
268280PyFunction_GetModule (PyObject * op )
269281{
@@ -454,6 +466,7 @@ static PyMemberDef func_memberlist[] = {
454466 {"__globals__" , T_OBJECT , OFF (func_globals ), READONLY },
455467 {"__module__" , T_OBJECT , OFF (func_module ), 0 },
456468 {"__builtins__" , T_OBJECT , OFF (func_builtins ), READONLY },
469+ {"__class_dict__" ,T_OBJECT , OFF (func_class_dict ), READONLY },
457470 {NULL } /* Sentinel */
458471};
459472
@@ -813,6 +826,7 @@ func_clear(PyFunctionObject *op)
813826 Py_CLEAR (op -> func_closure );
814827 Py_CLEAR (op -> func_annotations );
815828 Py_CLEAR (op -> func_typeparams );
829+ Py_CLEAR (op -> func_class_dict );
816830 // Don't Py_CLEAR(op->func_code), since code is always required
817831 // to be non-NULL. Similarly, name and qualname shouldn't be NULL.
818832 // However, name and qualname could be str subclasses, so they
@@ -868,6 +882,7 @@ func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
868882 Py_VISIT (f -> func_closure );
869883 Py_VISIT (f -> func_annotations );
870884 Py_VISIT (f -> func_typeparams );
885+ Py_VISIT (f -> func_class_dict );
871886 Py_VISIT (f -> func_qualname );
872887 return 0 ;
873888}
0 commit comments