[Python-Dev] Should we do away with unbound methods in Py3k?
Guido van Rossum
guido at python.org
Sat Nov 24 18:56:40 CET 2007
On Nov 23, 2007 11:10 PM, Christian Heimes <lists at cheimes.de> wrote:
> Guido van Rossum wrote:
> >
> > Index: Objects/funcobject.c
> > ===================================================================
> > --- Objects/funcobject.c (revision 59154)
> > +++ Objects/funcobject.c (working copy)
> > @@ -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);
> > }
> >
> > [well, except those should be tabs not spaces]
>
> I've created a preliminary patch. Several unit tests are still failing.
Thanks for the patch! Now I'm hoping someone will look into those
remaining six test failures.
Also, there was discussion of this before:
http://mail.python.org/pipermail/python-dev/2005-January/050625.html
-- why didn't we decide to do it then?
> The patch is also changing some semantics. For example in Python 2.5:
>
> >>> import inspect
> >>> class Class(object):
> ... def method(self): pass
> ...
> >>> inspect.ismethod(Class().method)
> True
> >>> inspect.ismethod(Class.method)
> True
>
> But in py3k:
>
> >>> import inspect
> >>> class Class:
> ... def method(self): pass
> ...
> >>> inspect.ismethod(Class().method)
> True
> >>> inspect.ismethod(Class.method)
> False # !!!
As it should be.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list