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 andrei.avk
Recipients andrei.avk, iritkatriel, jbw, kj, moi90, serhiy.storchaka
Date 2021-10-20.03:39:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634701178.87.0.818461803913.issue43656@roundup.psfhosted.org>
In-reply-to
Content
Joe:

I would argue that it should be expected that every object instantiated from a class should have a safe __repr__, because you will have logging and if a __repr__ is broken in some rare circumstances, it may bring down your production system in the worst case. 

Additionally, if you have some logic that handles error conditions and logs respective objects, and some of these objects have a broken __repr__, you may run into a situation where you have a rare bug, and as you use the logs to debug it, you will not be able to tell which object was involved because you will only see the traceback from the __repr__. You may have to wait for the rare bug to occur again to determine the cause.

To me it seems that this request is more for convenience of interactive debugging, which should not be a priority over system functional robustness and logging robustness.

In view of this, your example should be changed to something like:

class TriggerTracebackBug:
    _repr = None
    def __init__(self):
        raise RuntimeError("can't build a TriggerTracebackBug object for some reason")
        self._repr = 'if we reached this line, this object would have a repr result'
    def __repr__(self):
        return f'<Myclass: {self._repr}>'
History
Date User Action Args
2021-10-20 03:39:38andrei.avksetrecipients: + andrei.avk, serhiy.storchaka, iritkatriel, moi90, kj, jbw
2021-10-20 03:39:38andrei.avksetmessageid: <1634701178.87.0.818461803913.issue43656@roundup.psfhosted.org>
2021-10-20 03:39:38andrei.avklinkissue43656 messages
2021-10-20 03:39:38andrei.avkcreate