]> granicus.if.org Git - python/commitdiff
#2346/#2347: add py3k warning for __methods__ and __members__. Patch by Jack Diederich.
authorGeorg Brandl <georg@python.org>
Fri, 21 Mar 2008 20:21:46 +0000 (20:21 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 21 Mar 2008 20:21:46 +0000 (20:21 +0000)
Lib/test/test_py3kwarn.py
Misc/NEWS
Objects/methodobject.c
Objects/object.c

index aaa16231b940b30feee8f5e66b8dbb053c19e8b1..f030af09f7219d5384a00516ac74df848dea8384 100644 (file)
@@ -99,6 +99,16 @@ class TestPy3KWarnings(unittest.TestCase):
         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)
 
index a581247a0a870958a21040a1d05c0291e103cc4b..83903ef78082110e3f9ab97508b8e15197ae7b4e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2?
 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 *".
index 5b9a3643aa53e7cc4c15a4f01e50835e1aa654d9..16175f9e98c8fd7bdd3bd898b579a0ab52c1688c 100644 (file)
@@ -352,8 +352,15 @@ PyObject *
 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)
index a10ac7ce19f3e0e67e4d59d0f0b119261be026c0..4a66f4fee147ee8a7289a0522e4a9c220b3d3eea 100644 (file)
@@ -1687,6 +1687,16 @@ merge_list_attr(PyObject* dict, PyObject* obj, const char *attrname)
                                        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);