This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author geitda
Recipients brett.cannon, geitda, jcdlr, om364@, ppperry, terry.reedy
Date 2020-04-22.00:10:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587514228.95.0.886486773556.issue33065@roundup.psfhosted.org>
In-reply-to
Content
It looks like the IDLE debugger seems to call repr on objects to present in the Locals list, even before they've been properly initialized. If __repr__ needs to refer to variables that don't exist until __init__ is done (and I don't think it's unreasonable for __repr__ to assume that __init__ is indeed finished), the debugger either needs wait until __init__ has completed on any given instance before trying to repr it, or otherwise needs to catch a potentially very wide range of exceptions that might be raised from calling __repr__ so early. I prefer the latter solution, since any buggy code that (effectively) crashes on it's __repr__ (for whatever reason) will probably bring the debugger to it's knees.
I played around with pdb directly and can sort of get the same thing if I ask for __repr__ too early:

 1 Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
 2 Type "help", "copyright", "credits" or "license" for more information.
 3 >>> import data
 4 >>> import pdb
 5 >>> pdb.run("data.BinaryData(b'some data')")
 6 > <string>(1)<module>()
 7 (Pdb) step
 8 --Call--
 9 > c:\users\geitd\documents\python\data.py(4)__init__()
10 -> def __init__(self, data):
11 (Pdb) p self
12 (Pdb) p BinaryData.__repr__(self)
13 *** AttributeError: 'BinaryData' object has no attribute 'length'
14 (Pdb) step
15 > c:\users\geitd\documents\python\data.py(5)__init__()
16 -> if not data:
17 (Pdb) step
18 > c:\users\geitd\documents\python\data.py(7)__init__()
19 -> if len(data) <= 1:
20 (Pdb) step
21 > c:\users\geitd\documents\python\data.py(10)__init__()
22 -> self.data = data
23 (Pdb) step
24 > c:\users\geitd\documents\python\data.py(11)__init__()
25 -> self.length = len(data)
26 (Pdb) p self
27 (Pdb) p BinaryData.__repr__(self)
28 *** AttributeError: 'BinaryData' object has no attribute 'length'
29 (Pdb) step
30 --Return--
31 > c:\users\geitd\documents\python\data.py(11)__init__()->None
32 -> self.length = len(data)
33 (Pdb) p self
34 <BinaryData: length 9>
35 (Pdb) p BinaryData.__repr__(self)
36 '<BinaryData: length 9>'

Note that line 11 didn't return anything, but didn't have any bad results, whereas the way I phrased line 12 gave the exact same error the IDLE debugger threw.
Lines 26 and 27 towards the end of __init__ came out the same, but after the --Return-- on 30, either phrasing gives what you'd expect.
I suppose the TL;DR is to take the mechanism that gives the correct behavior of 'p self' in pdb and copy it over to the IDLE debugger (or whatever other mechanism is necessary).

Is this enough for you to work from?
History
Date User Action Args
2020-04-22 00:10:29geitdasetrecipients: + geitda, brett.cannon, terry.reedy, ppperry, jcdlr, om364@
2020-04-22 00:10:28geitdasetmessageid: <1587514228.95.0.886486773556.issue33065@roundup.psfhosted.org>
2020-04-22 00:10:28geitdalinkissue33065 messages
2020-04-22 00:10:28geitdacreate