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 terry.reedy
Recipients Trundle, aerojockey, barry, terry.reedy
Date 2011-03-19.00:41:49
SpamBayes Score 3.8857806e-16
Marked as misclassified No
Message-id <1300495310.36.0.352191959863.issue11603@psf.upfronthosting.co.za>
In-reply-to
Content
With 3.2 on WinXP, I get no error report in interactive mode,
with either IDLE or plain interpreter, nor from 'python file' in Command Prompt window. But now with the print added to what I ran before, I see no print output, and I see that IDLE is restarting after executing the code, so something *is* wrong. Further experiments with other print statements in various places show that 'str(foo)' is the specific culprit.

Appears to act same on 3.1 for me.

Patch is to this code (from 3.2, presume same otherwise):
==============================
static PyObject *
object_str(PyObject *self) 
{
    unaryfunc f;

    f = Py_TYPE(self)->tp_repr;
    if (f == NULL)
        f = object_repr;
    return f(self);
}
=============================
Patch prevent infinite recursion if f == object_str.
Whether or not this fixes issue ('should' is a bit vague, confirmation is needed) this seems like a good idea.

To be applied, patch should have a new testcase that fails without the patch and passes with it applied.
----
def test_NoCrashIfStrIsRepr(self)
  'see issue 11603'
  class Foo(object): # delete object for 3.x
    pass
  Foo.__repr__ = Foo.__str__
  foo = Foo()
  s = str(foo)
----
would be a start. I so not know if any AssertX is needed since just finishing would be a success. However, I also do not know where to put it as there is no test_object or test_typeobject file that I see.
History
Date User Action Args
2011-03-19 00:41:50terry.reedysetrecipients: + terry.reedy, barry, aerojockey, Trundle
2011-03-19 00:41:50terry.reedysetmessageid: <1300495310.36.0.352191959863.issue11603@psf.upfronthosting.co.za>
2011-03-19 00:41:49terry.reedylinkissue11603 messages
2011-03-19 00:41:49terry.reedycreate