[Python-3000-checkins] r56915 - in python/branches/py3k: Doc/lib/libstdtypes.tex Include/structmember.h Lib/test/test_descrtut.py Lib/test/test_traceback.py Misc/NEWS Misc/find_recursionlimit.py Modules/pyexpat.c Objects/methodobject.c PC/_winreg.c PC/os2emx/python25.def PC/os2vacpp/python.def Python/structmember.c Python/traceback.c Tools/modulator/Templates/object_structure

neal.norwitz python-3000-checkins at python.org
Sat Aug 11 08:39:54 CEST 2007


Author: neal.norwitz
Date: Sat Aug 11 08:39:53 2007
New Revision: 56915

Modified:
   python/branches/py3k/Doc/lib/libstdtypes.tex
   python/branches/py3k/Include/structmember.h
   python/branches/py3k/Lib/test/test_descrtut.py
   python/branches/py3k/Lib/test/test_traceback.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Misc/find_recursionlimit.py
   python/branches/py3k/Modules/pyexpat.c
   python/branches/py3k/Objects/methodobject.c
   python/branches/py3k/PC/_winreg.c
   python/branches/py3k/PC/os2emx/python25.def
   python/branches/py3k/PC/os2vacpp/python.def
   python/branches/py3k/Python/structmember.c
   python/branches/py3k/Python/traceback.c
   python/branches/py3k/Tools/modulator/Templates/object_structure
Log:
Remove support for __members__ and __methods__.  There still might be
some cleanup to do on this.  Particularly in Python/traceback.c with
getting rid of the getattr if possible and Demo/*metaclasses/Enum.py.



Modified: python/branches/py3k/Doc/lib/libstdtypes.tex
==============================================================================
--- python/branches/py3k/Doc/lib/libstdtypes.tex	(original)
+++ python/branches/py3k/Doc/lib/libstdtypes.tex	Sat Aug 11 08:39:53 2007
@@ -2051,16 +2051,6 @@
 object's (writable) attributes.
 \end{memberdesc}
 
-\begin{memberdesc}[object]{__methods__}
-\deprecated{2.2}{Use the built-in function \function{dir()} to get a
-list of an object's attributes.  This attribute is no longer available.}
-\end{memberdesc}
-
-\begin{memberdesc}[object]{__members__}
-\deprecated{2.2}{Use the built-in function \function{dir()} to get a
-list of an object's attributes.  This attribute is no longer available.}
-\end{memberdesc}
-
 \begin{memberdesc}[instance]{__class__}
 The class to which a class instance belongs.
 \end{memberdesc}

Modified: python/branches/py3k/Include/structmember.h
==============================================================================
--- python/branches/py3k/Include/structmember.h	(original)
+++ python/branches/py3k/Include/structmember.h	Sat Aug 11 08:39:53 2007
@@ -19,20 +19,12 @@
 #define offsetof(type, member) ( (int) & ((type*)0) -> member )
 #endif
 
-/* An array of memberlist structures defines the name, type and offset
+/* An array of PyMemberDef structures defines the name, type and offset
    of selected members of a C structure.  These can be read by
-   PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
-   is set).  The array must be terminated with an entry whose name
+   PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY
+   flag is set).  The array must be terminated with an entry whose name
    pointer is NULL. */
 
-struct memberlist {
-	/* Obsolete version, for binary backwards compatibility */
-	char *name;
-	int type;
-	int offset;
-	int flags;
-};
-
 typedef struct PyMemberDef {
 	/* Current version, use this */
 	char *name;
@@ -76,16 +68,11 @@
 
 /* Flags */
 #define READONLY	1
-#define RO		READONLY		/* Shorthand */
 #define READ_RESTRICTED	2
 #define WRITE_RESTRICTED 4
 #define RESTRICTED	(READ_RESTRICTED | WRITE_RESTRICTED)
 
 
-/* Obsolete API, for binary backwards compatibility */
-PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
-PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
-
 /* Current API, use this */
 PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
 PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);

Modified: python/branches/py3k/Lib/test/test_descrtut.py
==============================================================================
--- python/branches/py3k/Lib/test/test_descrtut.py	(original)
+++ python/branches/py3k/Lib/test/test_descrtut.py	Sat Aug 11 08:39:53 2007
@@ -162,15 +162,7 @@
     True
     >>>
 
-Under the new proposal, the __methods__ attribute no longer exists:
-
-    >>> [].__methods__
-    Traceback (most recent call last):
-      File "<stdin>", line 1, in ?
-    AttributeError: 'list' object has no attribute '__methods__'
-    >>>
-
-Instead, you can get the same information from the list type:
+You can get the information from the list type:
 
     >>> pprint.pprint(dir(list))    # like list.__dict__.keys(), but sorted
     ['__add__',

Modified: python/branches/py3k/Lib/test/test_traceback.py
==============================================================================
--- python/branches/py3k/Lib/test/test_traceback.py	(original)
+++ python/branches/py3k/Lib/test/test_traceback.py	Sat Aug 11 08:39:53 2007
@@ -52,14 +52,6 @@
         self.assert_("^" in err[2])
         self.assertEqual(err[1].find(")"), err[2].find("^"))
 
-    def test_members(self):
-        # Covers Python/structmember.c::listmembers()
-        try:
-            1/0
-        except:
-            import sys
-            sys.exc_info()[2].__members__
-
     def test_base_exception(self):
         # Test that exceptions derived from BaseException are formatted right
         e = KeyboardInterrupt()

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Aug 11 08:39:53 2007
@@ -75,6 +75,8 @@
   its argument, if it exists. If not, it will work like before. This allows
   customizing the output of dir() in the presence of a __getattr__().
 
+- Removed support for __members__ and __methods__.
+
 - Removed indexing/slicing on BaseException.
 
 - input() became raw_input(): the name input() now implements the
@@ -219,7 +221,7 @@
   __coerce__, __div__, __idiv__, __rdiv__
 
 - Removed these C APIs:
-  PyNumber_Coerce(), PyNumber_CoerceEx() 
+  PyNumber_Coerce(), PyNumber_CoerceEx(), PyMember_Get, PyMember_Set
 
 - Removed these C slots/fields:
   nb_divide, nb_inplace_divide
@@ -229,7 +231,8 @@
 
 - Removed these typedefs:
   intargfunc, intintargfunc, intobjargproc, intintobjargproc,
-  getreadbufferproc, getwritebufferproc, getsegcountproc, getcharbufferproc
+  getreadbufferproc, getwritebufferproc, getsegcountproc, getcharbufferproc,
+  memberlist
 
 
 Tests

Modified: python/branches/py3k/Misc/find_recursionlimit.py
==============================================================================
--- python/branches/py3k/Misc/find_recursionlimit.py	(original)
+++ python/branches/py3k/Misc/find_recursionlimit.py	Sat Aug 11 08:39:53 2007
@@ -17,8 +17,6 @@
 It ends when Python causes a segmentation fault because the limit is
 too high.  On platforms like Mac and Windows, it should exit with a
 MemoryError.
-
-NB: A program that does not use __methods__ can set a higher limit.
 """
 
 import sys

Modified: python/branches/py3k/Modules/pyexpat.c
==============================================================================
--- python/branches/py3k/Modules/pyexpat.c	(original)
+++ python/branches/py3k/Modules/pyexpat.c	Sat Aug 11 08:39:53 2007
@@ -1400,6 +1400,12 @@
         }
     }
 
+    return Py_FindMethod(xmlparse_methods, (PyObject *)self, name);
+}
+
+static PyObject *
+xmlparse_dir(PyObject *self, PyObject* noargs)
+{
 #define APPEND(list, str)				\
         do {						\
                 PyObject *o = PyString_FromString(str);	\
@@ -1408,36 +1414,39 @@
                 Py_XDECREF(o);				\
         } while (0)
 
-    if (strcmp(name, "__members__") == 0) {
-        int i;
-        PyObject *rc = PyList_New(0);
-	if (!rc)
-		return NULL;
-        for (i = 0; handler_info[i].name != NULL; i++) {
-            PyObject *o = get_handler_name(&handler_info[i]);
-            if (o != NULL)
-                PyList_Append(rc, o);
-            Py_XDECREF(o);
-        }
-        APPEND(rc, "ErrorCode");
-        APPEND(rc, "ErrorLineNumber");
-        APPEND(rc, "ErrorColumnNumber");
-        APPEND(rc, "ErrorByteIndex");
-        APPEND(rc, "CurrentLineNumber");
-        APPEND(rc, "CurrentColumnNumber");
-        APPEND(rc, "CurrentByteIndex");
-        APPEND(rc, "buffer_size");
-        APPEND(rc, "buffer_text");
-        APPEND(rc, "buffer_used");
-        APPEND(rc, "namespace_prefixes");
-        APPEND(rc, "ordered_attributes");
-        APPEND(rc, "specified_attributes");
-        APPEND(rc, "intern");
+    int i;
+    PyObject *rc = PyList_New(0);
+    if (!rc)
+	return NULL;
+    for (i = 0; handler_info[i].name != NULL; i++) {
+        PyObject *o = get_handler_name(&handler_info[i]);
+        if (o != NULL)
+            PyList_Append(rc, o);
+        Py_XDECREF(o);
+    }
+    APPEND(rc, "ErrorCode");
+    APPEND(rc, "ErrorLineNumber");
+    APPEND(rc, "ErrorColumnNumber");
+    APPEND(rc, "ErrorByteIndex");
+    APPEND(rc, "CurrentLineNumber");
+    APPEND(rc, "CurrentColumnNumber");
+    APPEND(rc, "CurrentByteIndex");
+    APPEND(rc, "buffer_size");
+    APPEND(rc, "buffer_text");
+    APPEND(rc, "buffer_used");
+    APPEND(rc, "namespace_prefixes");
+    APPEND(rc, "ordered_attributes");
+    APPEND(rc, "specified_attributes");
+    APPEND(rc, "intern");
 
 #undef APPEND
-        return rc;
+
+    if (PyErr_Occurred()) {
+        Py_DECREF(rc);
+        rc = NULL;
     }
-    return Py_FindMethod(xmlparse_methods, (PyObject *)self, name);
+
+    return rc;
 }
 
 static int
@@ -1560,6 +1569,10 @@
 
 PyDoc_STRVAR(Xmlparsetype__doc__, "XML parser");
 
+static PyMethodDef xmlparse_tp_methods[] = {
+    {"__dir__", xmlparse_dir, METH_NOARGS}
+};
+
 static PyTypeObject Xmlparsetype = {
 	PyVarObject_HEAD_INIT(NULL, 0)
 	"pyexpat.xmlparser",		/*tp_name*/
@@ -1588,7 +1601,12 @@
 #endif
 	Xmlparsetype__doc__, /* tp_doc - Documentation string */
 	(traverseproc)xmlparse_traverse,	/* tp_traverse */
-	(inquiry)xmlparse_clear		/* tp_clear */
+	(inquiry)xmlparse_clear,		/* tp_clear */
+	0,				/* tp_richcompare */
+	0,				/* tp_weaklistoffset */
+	0,				/* tp_iter */
+	0,				/* tp_iternext */
+	xmlparse_tp_methods		/* tp_methods */
 };
 
 /* End of code for xmlparser objects */

Modified: python/branches/py3k/Objects/methodobject.c
==============================================================================
--- python/branches/py3k/Objects/methodobject.c	(original)
+++ python/branches/py3k/Objects/methodobject.c	Sat Aug 11 08:39:53 2007
@@ -275,47 +275,12 @@
 	0,					/* tp_dict */
 };
 
-/* List all methods in a chain -- helper for findmethodinchain */
-
-static PyObject *
-listmethodchain(PyMethodChain *chain)
-{
-	PyMethodChain *c;
-	PyMethodDef *ml;
-	int i, n;
-	PyObject *v;
-
-	n = 0;
-	for (c = chain; c != NULL; c = c->link) {
-		for (ml = c->methods; ml->ml_name != NULL; ml++)
-			n++;
-	}
-	v = PyList_New(n);
-	if (v == NULL)
-		return NULL;
-	i = 0;
-	for (c = chain; c != NULL; c = c->link) {
-		for (ml = c->methods; ml->ml_name != NULL; ml++) {
-			PyList_SetItem(v, i, PyUnicode_FromString(ml->ml_name));
-			i++;
-		}
-	}
-	if (PyErr_Occurred()) {
-		Py_DECREF(v);
-		return NULL;
-	}
-	PyList_Sort(v);
-	return v;
-}
-
 /* Find a method in a method chain */
 
 PyObject *
 Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
 {
 	if (name[0] == '_' && name[1] == '_') {
-		if (strcmp(name, "__methods__") == 0)
-			return listmethodchain(chain);
 		if (strcmp(name, "__doc__") == 0) {
 			const char *doc = self->ob_type->tp_doc;
 			if (doc != NULL)

Modified: python/branches/py3k/PC/_winreg.c
==============================================================================
--- python/branches/py3k/PC/_winreg.c	(original)
+++ python/branches/py3k/PC/_winreg.c	Sat Aug 11 08:39:53 2007
@@ -473,8 +473,8 @@
 
 #define OFF(e) offsetof(PyHKEYObject, e)
 
-static struct memberlist PyHKEY_memberlist[] = {
-	{"handle",      T_INT,      OFF(hkey)},
+static PyMemberDef PyHKEY_memberlist[] = {
+	{"handle",      T_INT,      OFF(hkey), READONLY},
 	{NULL}    /* Sentinel */
 };
 
@@ -523,7 +523,10 @@
 	PyErr_Clear();
 	if (strcmp(name, "handle") == 0)
 		return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey);
-	return PyMember_Get((char *)self, PyHKEY_memberlist, name);
+	PyErr_Format(PyExc_AttributeError,
+                     "'%.50s' object has no attribute '%.400s'",
+                     Py_Type(self)->tp_name, name);
+	return NULL;
 }
 
 /************************************************************************

Modified: python/branches/py3k/PC/os2emx/python25.def
==============================================================================
--- python/branches/py3k/PC/os2emx/python25.def	(original)
+++ python/branches/py3k/PC/os2emx/python25.def	Sat Aug 11 08:39:53 2007
@@ -1091,10 +1091,8 @@
   "_Py_QnewFlag"
 
 ; From python25_s.lib(structmember)
-  "PyMember_Get"
   "PyMember_GetOne"
   "PyMember_SetOne"
-  "PyMember_Set"
 
 ; From python25_s.lib(symtable)
   "PySymtable_Build"

Modified: python/branches/py3k/PC/os2vacpp/python.def
==============================================================================
--- python/branches/py3k/PC/os2vacpp/python.def	(original)
+++ python/branches/py3k/PC/os2vacpp/python.def	Sat Aug 11 08:39:53 2007
@@ -244,8 +244,6 @@
                PyMem_Free
                PyMem_Malloc
                PyMem_Realloc
-               PyMember_Get
-               PyMember_Set
                PyMethod_Class
                PyMethod_Fini
                PyMethod_Function

Modified: python/branches/py3k/Python/structmember.c
==============================================================================
--- python/branches/py3k/Python/structmember.c	(original)
+++ python/branches/py3k/Python/structmember.c	Sat Aug 11 08:39:53 2007
@@ -5,51 +5,6 @@
 
 #include "structmember.h"
 
-static PyObject *
-listmembers(struct memberlist *mlist)
-{
-	int i, n;
-	PyObject *v;
-	for (n = 0; mlist[n].name != NULL; n++)
-		;
-	v = PyList_New(n);
-	if (v != NULL) {
-		for (i = 0; i < n; i++)
-			PyList_SetItem(v, i,
-				       PyString_FromString(mlist[i].name));
-		if (PyErr_Occurred()) {
-			Py_DECREF(v);
-			v = NULL;
-		}
-		else {
-			PyList_Sort(v);
-		}
-	}
-	return v;
-}
-
-PyObject *
-PyMember_Get(const char *addr, struct memberlist *mlist, const char *name)
-{
-	struct memberlist *l;
-
-	if (strcmp(name, "__members__") == 0)
-		return listmembers(mlist);
-	for (l = mlist; l->name != NULL; l++) {
-		if (strcmp(l->name, name) == 0) {
-			PyMemberDef copy;
-			copy.name = l->name;
-			copy.type = l->type;
-			copy.offset = l->offset;
-			copy.flags = l->flags;
-			copy.doc = NULL;
-			return PyMember_GetOne(addr, &copy);
-		}
-	}
-	PyErr_SetString(PyExc_AttributeError, name);
-	return NULL;
-}
-
 PyObject *
 PyMember_GetOne(const char *addr, PyMemberDef *l)
 {
@@ -135,27 +90,6 @@
 	return v;
 }
 
-int
-PyMember_Set(char *addr, struct memberlist *mlist, const char *name, PyObject *v)
-{
-	struct memberlist *l;
-
-	for (l = mlist; l->name != NULL; l++) {
-		if (strcmp(l->name, name) == 0) {
-			PyMemberDef copy;
-			copy.name = l->name;
-			copy.type = l->type;
-			copy.offset = l->offset;
-			copy.flags = l->flags;
-			copy.doc = NULL;
-			return PyMember_SetOne(addr, &copy, v);
-		}
-	}
-
-	PyErr_SetString(PyExc_AttributeError, name);
-	return -1;
-}
-
 #define WARN(msg)					\
     do {						\
 	if (PyErr_Warn(PyExc_RuntimeWarning, msg) < 0)	\

Modified: python/branches/py3k/Python/traceback.c
==============================================================================
--- python/branches/py3k/Python/traceback.c	(original)
+++ python/branches/py3k/Python/traceback.c	Sat Aug 11 08:39:53 2007
@@ -11,18 +11,28 @@
 
 #define OFF(x) offsetof(PyTracebackObject, x)
 
-static struct memberlist tb_memberlist[] = {
-	{"tb_next",	T_OBJECT,	OFF(tb_next)},
-	{"tb_frame",	T_OBJECT,	OFF(tb_frame)},
-	{"tb_lasti",	T_INT,		OFF(tb_lasti)},
-	{"tb_lineno",	T_INT,		OFF(tb_lineno)},
+static PyMemberDef tb_memberlist[] = {
+	{"tb_next",	T_OBJECT,	OFF(tb_next),	READONLY},
+	{"tb_frame",	T_OBJECT,	OFF(tb_frame),	READONLY},
+	{"tb_lasti",	T_INT,		OFF(tb_lasti),	READONLY},
+	{"tb_lineno",	T_INT,		OFF(tb_lineno),	READONLY},
 	{NULL}	/* Sentinel */
 };
 
+/* XXX(nnorwitz): can we get rid of tb_getattr and use tp_members? */
 static PyObject *
 tb_getattr(PyTracebackObject *tb, char *name)
 {
-	return PyMember_Get((char *)tb, tb_memberlist, name);
+	int i;
+	for (i = 0; tb_memberlist[i].name != NULL; i++) {
+		if (strcmp(name, tb_memberlist[i].name) == 0)
+			return PyMember_GetOne((const char *)tb,
+					       tb_memberlist + i);
+	}
+	PyErr_Format(PyExc_AttributeError,
+		     "'%.50s' object has no attribute '%.400s'",
+		     Py_Type(tb)->tp_name, name);
+	return NULL;
 }
 
 static void
@@ -80,8 +90,8 @@
 	0,					/* tp_iter */
 	0,					/* tp_iternext */
 	0,					/* tp_methods */
-	0,			/* tp_members */
-	0,			/* tp_getset */
+	0,					/* tp_members */
+	0,					/* tp_getset */
 	0,					/* tp_base */
 	0,					/* tp_dict */
 };

Modified: python/branches/py3k/Tools/modulator/Templates/object_structure
==============================================================================
--- python/branches/py3k/Tools/modulator/Templates/object_structure	(original)
+++ python/branches/py3k/Tools/modulator/Templates/object_structure	Sat Aug 11 08:39:53 2007
@@ -5,8 +5,8 @@
 
 #define OFF(x) offsetof(XXXXobject, x)
 
-static struct memberlist $abbrev$_memberlist[] = {
-	/* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
+static PyMemberDef $abbrev$_memberlist[] = {
+	/* XXXX Add lines like { "foo", T_INT, OFF(foo), READONLY }  */
 
 	{NULL}	/* Sentinel */
 };
@@ -17,7 +17,7 @@
 	PyObject *rv;
 	
 	/* XXXX Add your own getattr code here */
-	rv = PyMember_Get((char *)/*XXXX*/0, $abbrev$_memberlist, name);
+	rv = PyMember_GetOne((char *)/*XXXX*/0, &$abbrev$_memberlist[i]);
 	if (rv)
 		return rv;
 	PyErr_Clear();
@@ -33,5 +33,5 @@
 		PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
 		return -1;
 	}
-	return PyMember_Set((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
+	return PyMember_SetOne((char *)/*XXXX*/0, &$abbrev$_memberlist[i], v);
 }


More information about the Python-3000-checkins mailing list