diff options
author | Guido van Rossum <guido@python.org> | 1997-09-12 20:04:46 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-09-12 20:04:46 (GMT) |
commit | 7cc56eb524dd83e3ba9d76accec3b0fe4010a48a (patch) | |
tree | bd4ad6dc6d954bb1eb10640dee297422b810254e /Objects | |
parent | 626a8d034c7bdc6f716430c5d1535c09c6341fa3 (diff) | |
download | cpython-7cc56eb524dd83e3ba9d76accec3b0fe4010a48a.zip cpython-7cc56eb524dd83e3ba9d76accec3b0fe4010a48a.tar.gz cpython-7cc56eb524dd83e3ba9d76accec3b0fe4010a48a.tar.bz2 |
When creating a class, set its __module__ attribute to the module
whose name is in the current globals' __name__ variable. If __name__
is not set, ignore this.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/classobject.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 91307f8..1cbbcf7 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -47,16 +47,36 @@ PyClass_New(bases, dict, name) { PyClassObject *op, *dummy; static PyObject *getattrstr, *setattrstr, *delattrstr; - static PyObject *docstr; + static PyObject *docstr, *modstr, *namestr; if (docstr == NULL) { docstr= PyString_InternFromString("__doc__"); if (docstr == NULL) return NULL; } + if (modstr == NULL) { + modstr= PyString_InternFromString("__module__"); + if (modstr == NULL) + return NULL; + } + if (namestr == NULL) { + namestr= PyString_InternFromString("__name__"); + if (namestr == NULL) + return NULL; + } if (PyDict_GetItem(dict, docstr) == NULL) { if (PyDict_SetItem(dict, docstr, Py_None) < 0) return NULL; } + if (PyDict_GetItem(dict, modstr) == NULL) { + PyObject *globals = PyEval_GetGlobals(); + if (globals != NULL) { + PyObject *name = PyDict_GetItem(globals, namestr); + if (name != NULL) { + if (PyDict_SetItem(dict, modstr, name) < 0) + return NULL; + } + } + } if (bases == NULL) { bases = PyTuple_New(0); if (bases == NULL) @@ -114,6 +134,7 @@ class_lookup(cp, name, pclass) } n = PyTuple_Size(cp->cl_bases); for (i = 0; i < n; i++) { + /* XXX What if one of the bases is not a class? */ PyObject *v = class_lookup( (PyClassObject *) PyTuple_GetItem(cp->cl_bases, i), name, pclass); |