Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__repr__ is ignored when formatting exceptions #50132

Closed
ellisj mannequin opened this issue Apr 29, 2009 · 2 comments
Closed

__repr__ is ignored when formatting exceptions #50132

ellisj mannequin opened this issue Apr 29, 2009 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ellisj
Copy link
Mannequin

ellisj mannequin commented Apr 29, 2009

BPO 5882
Nosy @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-04-29.23:47:04.338>
created_at = <Date 2009-04-29.21:36:16.350>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = '__repr__ is ignored when formatting exceptions'
updated_at = <Date 2009-04-29.23:47:04.336>
user = 'https://bugs.python.org/ellisj'

bugs.python.org fields:

activity = <Date 2009-04-29.23:47:04.336>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2009-04-29.23:47:04.338>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2009-04-29.21:36:16.350>
creator = 'ellisj'
dependencies = []
files = []
hgrepos = []
issue_num = 5882
keywords = []
message_count = 2.0
messages = ['86826', '86835']
nosy_count = 2.0
nosy_names = ['ellisj', 'benjamin.peterson']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5882'
versions = ['Python 2.6', 'Python 3.0']

@ellisj
Copy link
Mannequin Author

ellisj mannequin commented Apr 29, 2009

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!

@ellisj ellisj mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Apr 29, 2009
@benjaminp
Copy link
Contributor

And Exception implements __str__, so it is called.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant