Bugs item #1605019, was opened at 2006-11-29 00:47
Message generated for change (Comment added) made by cgroves
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1605019&group_id=12867
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core
Group: targeted for 2.2beta1
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Charles Groves (cgroves)
Assigned to: Charles Groves (cgroves)
Summary: assigning a bound method to a class rebinds to instances
Initial Comment:
Assigning a method bound to an instance of a class C to a class D rebinds the method to instances of D instead of using the already bound instance C. This causes methods in test_descr to fail.
----------------------------------------------------------------------
>Comment By: Charles Groves (cgroves)
Date: 2007-01-30 23:44
Message:
Logged In: YES
user_id=1174327
Originator: YES
Fixed in r3067.
----------------------------------------------------------------------
Comment By: Samuele Pedroni (pedronis)
Date: 2006-12-21 00:55
Message:
Logged In: YES
user_id=61408
Originator: NO
the problem is very simple
a) further calls on the __get__ behavior of a bound method should simply
return the bound method untouched
(see
http://svn.python.org/view/python/trunk/Objects/classobject.c
instancemethod_descr_get
or https://codespeak.net/viewvc/pypy/dist/pypy/interpreter/function.py
def descr_method_get)
b) PyMethod is still 2.1 code, it needs to be converted to new-style
conventions
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 19:15
Message:
Logged In: YES
user_id=1277399
Originator: NO
This article is instructive about descriptors:
http://users.rcn.com/python/download/Descriptor.htm
It appears that unbound methods are descriptors and if passed in an Object
it they need to create a bound method to the Object.
leouser
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 16:51
Message:
Logged In: YES
user_id=1277399
Originator: NO
oh yeah,
there are worlds of differences between CPython and Jythons bound and
unbound methods:
Jython:
>>> class x:
... def zoo(self):
... print "Zoo"
>>> a = x.zoo
>>> dir(a)
['__dict__', '__doc__', '__name__', 'im_class', 'im_func', 'im_self']
Python:
>>> class z:
... def mork(self):
... print "mork"
...
>>> x = z.mork
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__',
'__get attribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class',
'im_func', 'im_self']
leouser
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 16:33
Message:
Logged In: YES
user_id=1277399
Originator: NO
The final bomb can be navigated through by giving the PyMethod a
dictionary with a __get__ function. This in turn requires _doget to be
further enhanced to create a new PyMethod if the container is null but
wherefrom is not null. wherefrom is used as the "self" argument. Also
the toString needs to return a "bound method" instead of a "method"
string.
Im trying to locate the spec for a unbound methods + __get__ invocations
to see if there is clear behavior as what to do with it.
leouser
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 15:56
Message:
Logged In: YES
user_id=1277399
Originator: NO
Ahh, I see the bug. This is odd, since I would expect a PyMethod to be
there, which would be bound to C. Ill have to see what's up.
leouser
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 15:41
Message:
Logged In: YES
user_id=1277399
Originator: NO
Well, the method is created in PyMethod _doget.
>From altering this line in _doget:
if (__builtin__.issubclass(container.fastGetClass(), im_class))
To:
if (__builtin__.issubclass(container.fastGetClass(), im_class) && im_self
== null){
the code moves further along in the test, but bombs here:
verify(repr(C.foo.__get__(C(1))).startswith("<bound method "))
at the last line in methods. Ill see what the deal is here.
Im trying to think if the == null makes sense as a test. It guards
against the problem, but what else can go wrong.
leouser
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 15:05
Message:
Logged In: YES
user_id=1277399
Originator: NO
Ahh, I see the bug. This is odd, since I would expect a PyMethod to be
there, which would be bound to C. Ill have to see what's up.
leouser
----------------------------------------------------------------------
Comment By: Khalid Zuberi (kzuberi)
Date: 2006-12-20 14:25
Message:
Logged In: YES
user_id=18288
Originator: NO
Leo, if you haven't already, try running the test 'methods()' from
test_descr.py (which currently fails for me) and see if you can find the
cause of the failure.
- kz
----------------------------------------------------------------------
Comment By: leouser (leouserz)
Date: 2006-12-20 14:12
Message:
Logged In: YES
user_id=1277399
Originator: NO
Im trying to understand the bug here. Ive got a test case together:
class x:
def zoom1(self):
print self
class z:
pass
a = x()
a.zoom1()
t = z()
z.zoom1 = a.zoom1
t.zoom1()
and they do the same thing for me in Python as in Jython.
leouser
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1605019&group_id=12867
|