[Python-checkins] r55606 - in python/trunk: Misc/NEWS Objects/funcobject.c

neal.norwitz python-checkins at python.org
Sun May 27 06:09:03 CEST 2007


Author: neal.norwitz
Date: Sun May 27 06:08:54 2007
New Revision: 55606
Modified:
 python/trunk/Misc/NEWS
 python/trunk/Objects/funcobject.c
Log:
Add the new function object attribute names from py3k.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun May 27 06:08:54 2007
@@ -12,6 +12,9 @@
 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.
 
Modified: python/trunk/Objects/funcobject.c
==============================================================================
--- python/trunk/Objects/funcobject.c	(original)
+++ python/trunk/Objects/funcobject.c	Sun May 27 06:08:54 2007
@@ -161,10 +161,14 @@
 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 @@
 	 * 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 @@
 	 * 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 @@
 		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 @@
 
 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},


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /