summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_py3kwarn.py10
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/methodobject.c9
-rw-r--r--Objects/object.c10
4 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_py3kwarn.py b/Lib/test/test_py3kwarn.py
index aaa1623..f030af0 100644
--- a/Lib/test/test_py3kwarn.py
+++ b/Lib/test/test_py3kwarn.py
@@ -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)
diff --git a/Misc/NEWS b/Misc/NEWS
index a581247..83903ef 100644
--- 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 *".
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 5b9a364..16175f9 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -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)
diff --git a/Objects/object.c b/Objects/object.c
index a10ac7c..4a66f4f 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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);