less verbose subtyping Py/C API code, use PyObject_CallFunction which supports packin...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 22 Jul 2009 19:50:21 +0000 (19:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 22 Jul 2009 19:50:21 +0000 (19:50 +0000)
source/blender/python/intern/bpy_rna.c

index 7319a269ffbdd6775a3061033299bcd3cc0de71d..be98a985ac2241e0a097cd82bb0550ee3d9bcd7f 100644 (file)
@@ -2300,31 +2300,23 @@ PyObject* pyrna_srna_Subtype(StructRNA *srna)
        } else if ((newclass= RNA_struct_py_type_get(srna))) {
                Py_INCREF(newclass);
        } else {
-               StructRNA *base;
-               
-               /* for now, return the base RNA type rather then a real module */
-               
-               /* Assume RNA_struct_py_type_get(srna) was alredy checked */
-               
                /* subclass equivelents
                - class myClass(myBase):
                        some='value' # or ...
                - myClass = type(name='myClass', bases=(myBase,), dict={'__module__':'bpy.types'})
                */
-               const char *descr= RNA_struct_ui_description(srna);
 
-               PyObject *args = PyTuple_New(3);
-               PyObject *bases = PyTuple_New(1);
+               /* Assume RNA_struct_py_type_get(srna) was alredy checked */
+               StructRNA *base;
+
                PyObject *py_base= NULL;
-               PyObject *dict = PyDict_New();
-               PyObject *item;
-       
-               
-               // arg 1
-               //PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(tp_name));
-               PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(RNA_struct_identifier(srna)));
+
+               const char *idname= RNA_struct_identifier(srna);
+               const char *descr= RNA_struct_ui_description(srna);
+
+               if(!descr) descr= "(no docs)";
                
-               // arg 2
+               /* get the base type */
                base= RNA_struct_base(srna);
                if(base && base != srna) {
                        /*/printf("debug subtype %s %p\n", RNA_struct_identifier(srna), srna); */
@@ -2336,33 +2328,7 @@ PyObject* pyrna_srna_Subtype(StructRNA *srna)
                        Py_INCREF(py_base);
                }
                
-               PyTuple_SET_ITEM(bases, 0, py_base);
-
-               PyTuple_SET_ITEM(args, 1, bases);
-               
-               // arg 3 - add an instance of the rna 
-               if(descr) {
-                       item= PyUnicode_FromString(descr);
-                       PyDict_SetItemString(dict, "__doc__", item);
-                       Py_DECREF(item);
-               }
-               
-               /* this isnt needed however its confusing if we get python script names in blender types,
-                * because the __module__ is used when printing the class */
-               item= PyUnicode_FromString("bpy.types"); /* just to know its an internal type */
-               PyDict_SetItemString(dict, "__module__", item);
-               Py_DECREF(item);
-               
-               
-               PyTuple_SET_ITEM(args, 2, dict); // fill with useful subclass things!
-               
-               if (PyErr_Occurred()) {
-                       PyErr_Print();
-                       PyErr_Clear();
-               }
-               
-               newclass = PyObject_CallObject((PyObject *)&PyType_Type, args);
-               Py_DECREF(args);
+               newclass = PyObject_CallFunction(       (PyObject*)&PyType_Type, "s(N){ssss}", idname, py_base, "__module__","bpy.types", "__doc__",descr);
 
                if (newclass) {
                        pyrna_subtype_set_rna(newclass, srna);