Andrei Kulakov <andrei....@gmail.com> added the comment:
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}>' ---------- nosy: +kj _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43656> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com