You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unicode(x) for weakref.proxy objects invokes __str__ instead of __unicode__ #49287
changed the title [-]unexpected unicode behavior for proxy objects[/-][+]unicode(x) for weakref.proxy objects invokes __str__ instead of __unicode__[/+]on Jan 24, 2009
This was broken by r64791. The problem is that PyObject_Unicode now uses
_PyType_Lookup instead of PyObject_GetItem, so that the proxy's custom
__getattr__ implementation is bypassed.
weakref.proxy needs to be fixed to delegate the unicode slot correctly.
>>> from weakref import proxy
>>> "__unicode__"indir(type(proxy(Exception)))
False
That predicate must return true in order for the delegation to do the
right thing (this is actually the case for all of the slots and
pseudo-slots that can bypass __getattribute__ on the instance object -
it's just that most of them are already handled correctly).
This need to explicitly delegate all supported slots is the reason why
weakref proxy instances add so many magic method stubs when compared to
the actual interface of the underlying class:
Activity
Taldor commentedon Jan 23, 2009
Calling the unicode function on a proxy object, doesn't use the proxi-ed
object's __unicode__ method, but its __str__ method.
I expected the last result to be u'unicode'. I did get u'unicode' in
Python 2.5 (but not in 2.6).
ggenellina commentedon Jan 24, 2009
Same results on trunk.
[-]unexpected unicode behavior for proxy objects[/-][+]unicode(x) for weakref.proxy objects invokes __str__ instead of __unicode__[/+]benjaminp commentedon Jan 24, 2009
This was broken by r64791. The problem is that PyObject_Unicode now uses
_PyType_Lookup instead of PyObject_GetItem, so that the proxy's custom
__getattr__ implementation is bypassed.
ncoghlan commentedon Jan 24, 2009
weakref.proxy needs to be fixed to delegate the unicode slot correctly.
That predicate must return true in order for the delegation to do the
right thing (this is actually the case for all of the slots and
pseudo-slots that can bypass __getattribute__ on the instance object -
it's just that most of them are already handled correctly).
This need to explicitly delegate all supported slots is the reason why
weakref proxy instances add so many magic method stubs when compared to
the actual interface of the underlying class:
benjaminp commentedon Jan 24, 2009
Here's a patch.
ncoghlan commentedon Nov 18, 2009
Patch looks good to me.
benjaminp commentedon Nov 19, 2009
Fixed in r76395.