diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2007-05-27 04:08:54 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2007-05-27 04:08:54 (GMT) |
commit | 0ac601995ccd123696b44b0194c3718f8d364c07 (patch) | |
tree | 965c2ff7e3f39b6fc848619bba4c5426c206d7b6 | |
parent | 81a191b3510bbed302cb0a766bc6966cb4effaca (diff) | |
download | cpython-0ac601995ccd123696b44b0194c3718f8d364c07.zip cpython-0ac601995ccd123696b44b0194c3718f8d364c07.tar.gz cpython-0ac601995ccd123696b44b0194c3718f8d364c07.tar.bz2 |
Add the new function object attribute names from py3k.
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/funcobject.c | 13 |
2 files changed, 13 insertions, 3 deletions
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1? Core and builtins ----------------- +- Add new attribute names for function objects. All the func_* become + __*__ attributes. (Some already existed, e.g., __doc__ and __name__.) + - Add -3 option to the interpreter to warn about features that are deprecated and will be changed/removed in Python 3.0. diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 1ba74c5..190765a 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -161,10 +161,14 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure) static PyMemberDef func_memberlist[] = { {"func_closure", T_OBJECT, OFF(func_closure), RESTRICTED|READONLY}, + {"__closure__", T_OBJECT, OFF(func_closure), + RESTRICTED|READONLY}, {"func_doc", T_OBJECT, OFF(func_doc), WRITE_RESTRICTED}, {"__doc__", T_OBJECT, OFF(func_doc), WRITE_RESTRICTED}, {"func_globals", T_OBJECT, OFF(func_globals), RESTRICTED|READONLY}, + {"__globals__", T_OBJECT, OFF(func_globals), + RESTRICTED|READONLY}, {"__module__", T_OBJECT, OFF(func_module), WRITE_RESTRICTED}, {NULL} /* Sentinel */ }; @@ -240,7 +244,7 @@ func_set_code(PyFunctionObject *op, PyObject *value) * other than a code object. */ if (value == NULL || !PyCode_Check(value)) { PyErr_SetString(PyExc_TypeError, - "func_code must be set to a code object"); + "__code__ must be set to a code object"); return -1; } nfree = PyCode_GetNumFree((PyCodeObject *)value); @@ -279,7 +283,7 @@ func_set_name(PyFunctionObject *op, PyObject *value) * other than a string object. */ if (value == NULL || !PyString_Check(value)) { PyErr_SetString(PyExc_TypeError, - "func_name must be set to a string object"); + "__name__ must be set to a string object"); return -1; } tmp = op->func_name; @@ -315,7 +319,7 @@ func_set_defaults(PyFunctionObject *op, PyObject *value) value = NULL; if (value != NULL && !PyTuple_Check(value)) { PyErr_SetString(PyExc_TypeError, - "func_defaults must be set to a tuple object"); + "__defaults__ must be set to a tuple object"); return -1; } tmp = op->func_defaults; @@ -327,8 +331,11 @@ func_set_defaults(PyFunctionObject *op, PyObject *value) static PyGetSetDef func_getsetlist[] = { {"func_code", (getter)func_get_code, (setter)func_set_code}, + {"__code__", (getter)func_get_code, (setter)func_set_code}, {"func_defaults", (getter)func_get_defaults, (setter)func_set_defaults}, + {"__defaults__", (getter)func_get_defaults, + (setter)func_set_defaults}, {"func_dict", (getter)func_get_dict, (setter)func_set_dict}, {"__dict__", (getter)func_get_dict, (setter)func_set_dict}, {"func_name", (getter)func_get_name, (setter)func_set_name}, |