[issue11603] Python crashes or hangs when rebinding __repr__ as __str__

Andreas Stührk report at bugs.python.org
Sun Mar 20 05:41:58 CET 2011


Andreas Stührk <andy-python at hammerhartes.de> added the comment:

On Sat, Mar 19, 2011 at 12:41 AM, Terry J. Reedy <report at bugs.python.org> wrote:
> Whether or not this fixes issue ('should' is a bit vague, confirmation is needed) this seems like a good idea.

Yes, it fixes the issue. I wrote "should" because I was a bit in a
hurry and hadn't put much thought into whether it's the best way to
fix that issue (or if there even is an issue that should be fixed).
Now that I thought a bit more about it, I think it's a decent fix for
the issue. There is still the possibility that a custom __repr__
method calls `object.__str__`, but that will either raise a
RuntimeError at some point (due to stack exhaustion; if the method is
a Python method) or it's a case of "well, don't do that" (if the
method is implemented in C).

> However, I also do not know where to put it as there is no test_object or test_typeobject file that I see.

I updated the patch and put a test into test_class which seemed like a
good place for it to me. Also, I did the patch against the 3.1 branch
this time, so it can be forward-ported.

----------

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


More information about the Python-bugs-list mailing list