This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author grahamd
Recipients grahamd, ncoghlan, shishkander, tim.peters
Date 2013-10-07.08:22:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1381134155.27.0.591353175008.issue19070@psf.upfronthosting.co.za>
In-reply-to
Content
@shishkander I can't see how what you are talking about has got anything to do with the issue with in place operators. The results from your test script are expected and normal.

What result are you expecting?

The one thing you cannot override in Python is what type() returns for an object. Thus is it completely normal for the weakref.proxy object to have a different type that what it wraps.

This is one of the reasons why in Python why should rarely ever do direct comparison of type objects. Instead you should use isinstance().

>>> import weakref
>>> class Test(object):
...     pass
...
>>> test = Test()
>>> proxy = weakref.proxy(test)
>>> type(test)
<class '__main__.Test'>
>>> type(proxy)
<type 'weakproxy'>
>>> isinstance(test, Test)
True
>>> isinstance(proxy, Test)
True
>>> proxy.__class__
<class '__main__.Test'>

The isinstance() check will work because weakref.proxy will proxy __class__() method such that it returns the type of the wrapped object rather than of the proxy.

Now if your problem is with methods of wrapped objects which return self not having that self object some how automatically wrapped in another proxy, there isn't anything the proxy can be do about that. That is a situation where you as a user need to be careful about what you are doing. A way one can handle that is through derivation off a proxy object and override specific methods where you then in turn need to wrap the result, but I can see that easily becoming fragile when weakrefs are involved. Also, the weakref proxy in Python doesn't expose a class for doing that anyway.

One important thing to note is that where self is returned is returned by a normal method, it is still on you to have assigned the result to a variable so as to have started any possible problems. In the case of in place operators that is done under the covers by Python and you have no control over it. This is why the current behaviour as originally described is arguably broken as is breaks the expectations of what would logically happen for an in place operator when used via a proxy, something you have no control over.

So can you go back and explain what your specific problem is that you believe is the same issue as this bug report is, because so far I can't see any similarity based on your example code.
History
Date User Action Args
2013-10-07 08:22:35grahamdsetrecipients: + grahamd, tim.peters, ncoghlan, shishkander
2013-10-07 08:22:35grahamdsetmessageid: <1381134155.27.0.591353175008.issue19070@psf.upfronthosting.co.za>
2013-10-07 08:22:35grahamdlinkissue19070 messages
2013-10-07 08:22:34grahamdcreate