classification
Title: __repr__ is ignored when formatting exceptions
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, ellisj
Priority: normal Keywords:

Created on 2009-04-29 21:36 by ellisj, last changed 2009-04-29 23:47 by benjamin.peterson. This issue is now closed.

Messages (2)
msg86826 - (view) Author: Jonathan Ellis (ellisj) Date: 2009-04-29 21:36
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!
msg86835 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-04-29 23:47
And Exception implements __str__, so it is called.
History
Date User Action Args
2009-04-29 23:47:04benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg86835

resolution: not a bug
2009-04-29 21:37:23ellisjsetversions: + Python 3.0
2009-04-29 21:36:16ellisjcreate