[issue5882] __repr__ is ignored when formatting exceptions
Jonathan Ellis
report at bugs.python.org
Wed Apr 29 23:36:18 CEST 2009
New submission from Jonathan Ellis <ellisj at users.sourceforge.net>:
The docs say that "If a class defines __repr__() but not __str__(), then
__repr__() is also used when an “informal” string representation of
instances of that class is required."
but, repr is ignored:
>>> class E(Exception):
... def __repr__(self):
... return 'fancy!'
...
>>> raise E()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.E
only str is respected:
>>> class E(Exception):
... def __str__(self):
... return 'fancy!'
...
>>> raise E()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.E: fancy!
----------
components: Interpreter Core
messages: 86826
nosy: ellisj
severity: normal
status: open
title: __repr__ is ignored when formatting exceptions
type: behavior
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5882>
_______________________________________
More information about the Python-bugs-list
mailing list