[issue5037] unicode(x) for weakref.proxy objects invokes __str__ instead of __unicode__

Nick Coghlan report at bugs.python.org
Sat Jan 24 16:34:21 CET 2009


Nick Coghlan <ncoghlan at gmail.com> added the comment:

weakref.proxy needs to be fixed to delegate the unicode slot correctly.

>>> from weakref import proxy
>>> "__unicode__" in dir(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:

>>> len(set(dir(type(proxy(Exception)))) - set(dir(Exception)))
53

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5037>
_______________________________________


More information about the Python-bugs-list mailing list