[Python-checkins] r61715 - in python/trunk: Lib/test/test_py3kwarn.py Misc/NEWS Objects/methodobject.c Objects/object.c

georg.brandl python-checkins at python.org
Fri Mar 21 21:21:46 CET 2008


Author: georg.brandl
Date: Fri Mar 21 21:21:46 2008
New Revision: 61715

Modified:
   python/trunk/Lib/test/test_py3kwarn.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/methodobject.c
   python/trunk/Objects/object.c
Log:
#2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.


Modified: python/trunk/Lib/test/test_py3kwarn.py
==============================================================================
--- python/trunk/Lib/test/test_py3kwarn.py	(original)
+++ python/trunk/Lib/test/test_py3kwarn.py	Fri Mar 21 21:21:46 2008
@@ -99,6 +99,16 @@
         with catch_warning() as w:
             self.assertWarning(sys.exc_clear(), w, expected)
 
+    def test_methods_members(self):
+        expected = '__members__ and __methods__ not supported in 3.x'
+        class C:
+            __methods__ = ['a']
+            __members__ = ['b']
+        c = C()
+        with catch_warning() as w:
+            self.assertWarning(dir(c), w, expected)
+
+
 def test_main():
     run_unittest(TestPy3KWarnings)
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Mar 21 21:21:46 2008
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
  
+- Issue #2346/#2347: add Py3k warnings for __methods__ and __members__.
+
 - Issue #2358: Add a Py3k warning on sys.exc_clear() usage.
 
 - Issue #2400: Allow relative imports to "import *".

Modified: python/trunk/Objects/methodobject.c
==============================================================================
--- python/trunk/Objects/methodobject.c	(original)
+++ python/trunk/Objects/methodobject.c	Fri Mar 21 21:21:46 2008
@@ -352,8 +352,15 @@
 Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
 {
 	if (name[0] == '_' && name[1] == '_') {
-		if (strcmp(name, "__methods__") == 0)
+		if (strcmp(name, "__methods__") == 0) {
+			if (Py_Py3kWarningFlag) {
+				if (PyErr_Warn(PyExc_DeprecationWarning,
+					       "__methods__ not supported "
+					       "in 3.x") < 0)
+					return NULL;
+			}
 			return listmethodchain(chain);
+		}
 		if (strcmp(name, "__doc__") == 0) {
 			const char *doc = self->ob_type->tp_doc;
 			if (doc != NULL)

Modified: python/trunk/Objects/object.c
==============================================================================
--- python/trunk/Objects/object.c	(original)
+++ python/trunk/Objects/object.c	Fri Mar 21 21:21:46 2008
@@ -1687,6 +1687,16 @@
 					break;
 			}
 		}
+		if (Py_Py3kWarningFlag &&
+		    (strcmp(attrname, "__members__") == 0 ||
+		     strcmp(attrname, "__methods__") == 0)) {
+			if (PyErr_Warn(PyExc_DeprecationWarning, 
+				       "__members__ and __methods__ not supported "
+				       "in 3.x") < 0) {
+				Py_XDECREF(list);
+				return -1;
+			}
+		}
 	}
 
 	Py_XDECREF(list);


More information about the Python-checkins mailing list