New submission from Christian Heimes:
Here is a first patch to remove unbound method objects.
6 tests failed:
test_descr test_inspect test_pyclbr test_typechecks test_unittest
test_weakref
--
assignee: gvanrossum
components: Interpreter Core
files: py3k_remove_unbound.patch
keywords: patch, py3k
messages: 57798
nosy: gvanrossum, tiran
priority: high
severity: normal
status: open
title: Patch to remove unbound methods
type: rfe
versions: Python 3.0
Added file: http://bugs.python.org/file8799/py3k_remove_unbound.patch
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1493
__Index: Objects/funcobject.c
===
--- Objects/funcobject.c (Revision 59163)
+++ Objects/funcobject.c (Arbeitskopie)
@@ -643,8 +643,10 @@
static PyObject *
func_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
- if (obj == Py_None)
- obj = NULL;
+ if (obj == Py_None || obj == NULL) {
+ Py_INCREF(func);
+ return func;
+ }
return PyMethod_New(func, obj, type);
}
Index: Lib/DocXMLRPCServer.py
===
--- Lib/DocXMLRPCServer.py (Revision 59163)
+++ Lib/DocXMLRPCServer.py (Arbeitskopie)
@@ -74,7 +74,7 @@
title = 'a name=%sstrong%s/strong/a' % (anchor, name)
if inspect.ismethod(object):
-args, varargs, varkw, defaults = inspect.getargspec(object.im_func)
+args, varargs, varkw, defaults = inspect.getargspec(object)
# exclude the argument bound to the instance, it will be
# confusing to the non-Python user
argspec = inspect.formatargspec (
Index: Lib/test/test_extcall.py
===
--- Lib/test/test_extcall.py (Revision 59163)
+++ Lib/test/test_extcall.py (Arbeitskopie)
@@ -231,18 +231,8 @@
x = Foo()
print(Foo.method(*(x, 1, 2)))
print(Foo.method(x, *(1, 2)))
-try:
-print(Foo.method(*(1, 2, 3)))
-except TypeError as err:
-pass
-else:
-print('expected a TypeError for unbound method call')
-try:
-print(Foo.method(1, *(2, 3)))
-except TypeError as err:
-pass
-else:
-print('expected a TypeError for unbound method call')
+print(Foo.method(*(1, 2, 3)))
+print(Foo.method(1, *(2, 3)))
# A PyCFunction that takes only positional parameters should allow an
# empty keyword dictionary to pass without a complaint, but raise a
Index: Lib/test/test_repr.py
===
--- Lib/test/test_repr.py (Revision 59163)
+++ Lib/test/test_repr.py (Arbeitskopie)
@@ -280,8 +280,8 @@
''')
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
# Unbound methods first
-eq(repr(qux..amethod),
-'unbound method .amethod')
+self.failUnless(repr(qux..amethod).startswith(
+'function amethod'))
# Bound method next
iqux = qux.()
self.failUnless(repr(iqux.amethod).startswith(
Index: Lib/test/test_descrtut.py
===
--- Lib/test/test_descrtut.py (Revision 59163)
+++ Lib/test/test_descrtut.py (Arbeitskopie)
@@ -444,9 +444,7 @@
... B.foo(self)
C().foo()
-Traceback (most recent call last):
- ...
-TypeError: unbound method foo() must be called with B instance as first argument (got C instance instead)
+called A.foo()
class C(A):
... def foo(self):
Index: Lib/test/test_descr.py
===
--- Lib/test/test_descr.py (Revision 59163)
+++ Lib/test/test_descr.py (Arbeitskopie)
@@ -280,12 +280,12 @@
c = C()
vereq(interesting(dir(c)), cstuff)
-verify('im_self' in dir(C.Cmethod))
+#verify('im_self' in dir(C.Cmethod))
c.cdata = 2
c.cmethod = lambda self: 0
vereq(interesting(dir(c)), cstuff + ['cdata', 'cmethod'])
-verify('im_self' in dir(c.Cmethod))
+#verify('im_self' in dir(c.Cmethod))
class A(C):
Adata = 1
@@ -293,13