[Python-bugs-list] [ python-Bugs-666958 ] repr.repr not always safe
SourceForge.net
noreply@sourceforge.net
Sun, 12 Jan 2003 20:34:56 -0800
Bugs item #666958, was opened at 2003-01-12 23:17
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=666958&group_id=5470
Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Bob Ippolito (etrepum)
Assigned to: Nobody/Anonymous (nobody)
Summary: repr.repr not always safe
Initial Comment:
>>> class A:
... def __repr__(self):
... raise Exception
... def someMethod(self):
... pass
...
>>> A()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in __repr__
Exception
>>> repr.repr(A())
'<A instance at 237360>'
>>> repr.repr(A().someMethod)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/repr.py", line 15, in repr
return self.repr1(x, self.maxlevel)
File "/usr/lib/python2.2/repr.py", line 24, in repr1
s = `x`
File "<stdin>", line
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2003-01-12 23:34
Message:
Logged In: YES
user_id=31435
Why do say this is a bug? If you raise an exception, yes,
you get an exception. Most __repr__ *implementations*
try hard not to raise any exceptions, but it's never
guaranteed that they won't. For example, just about any
__repr__ implementation may run out of memory while
trying to build its result string, so MemoryError is almost
always a possible exception.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=666958&group_id=5470