Re: bug in the debuggers (pdb and wdb): Can't single step object creation

Guido.van.Rossum@cwi.nl
Tue, 01 Mar 1994 10:49:01 +0100

> If you step through object creation in the debugger,
> it tries to print the object before it has been fully initialized.
>
> Similar errors happen if you try stepping through the
> Date class initialization.
>
> The error only happens if you are using the debugger and stepping.

Turns out the debuggers use an ancient module "repr" which was written
before classes could override the meaning of `x` by defining a
__repr__ method. An error in the evaluation of `x` would not be
caught. The remedy is easy and will be part of release 1.0.2. A
sneak preview is below.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>

===================================================================
RCS file: /hosts/voorn/ufs/guido/python-RCS/new/Lib/RCS/repr.py,v
retrieving revision 1.2
diff -c -r1.2 repr.py
*** 1.2 1993/12/17 15:25:14
--- repr.py 1994/03/01 09:47:40
***************
*** 77,82 ****
--- 77,95 ----
j = max(0, self.maxlong-3-i)
s = s[:i] + '...' + s[len(s)-j:]
return s
+ def repr_instance(self, x, level):
+ try:
+ s = `x`
+ # Bugs in x.__repr__() can cause arbitrary
+ # exceptions -- then make up something
+ except:
+ return '<' + x.__class__.__name__ + ' instance at ' + \
+ hex(id(x))[2:] + '>'
+ if len(s) > self.maxstring:
+ i = max(0, (self.maxstring-3)/2)
+ j = max(0, self.maxstring-3-i)
+ s = s[:i] + '...' + s[len(s)-j:]
+ return s

aRepr = Repr()
repr = aRepr.repr