[Python-ideas] New Python syntax for continuing definitions for existing classes

Chris Angelico rosuav at gmail.com
Tue Sep 13 14:18:17 EDT 2016


On Wed, Sep 14, 2016 at 2:22 AM, nate lust <natelust at linux.com> wrote:
> I have written a functional reference implementation for the proposed
> continue class syntax which can be found at
> https://raw.githubusercontent.com/natelust/continueClassCpythonPatch/master/continueClass.patch
> .

AIUI, the central core to this code is:

+    /* Iterate over the dictionary which was populated in the eval call.
+       Set an attribute in the class corresponding to the key, item pair
+       generated by the eval statement */
+    dict_size = PyDict_Size(newdict);
+    dictkeys = PyDict_Keys(newdict);
+    for (i = 0; i < dict_size; i++ ){
+        key = PyList_GetItem(dictkeys, i);
+        item = PyDict_GetItem(newdict, key);
+        PyObject_SetAttr(aclass, key, item);
+    }

How does this handle special elements such as __module__, __dict__,
and __doc__? Does it overwrite them?

ChrisA


More information about the Python-ideas mailing list