Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81f87bb

Browse files
authored
bpo-33065: Fix problem debugging user classes with __repr__ method (GH-24183)
If __repr__ uses instance attributes, as normal, and one steps through the __init__ method, debugger may try to get repr before the instance attributes exist. reprlib.repr handles the error.
1 parent d16f617 commit 81f87bb

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Released on 2021-10-04?
33
======================================
44

55

6+
bpo-33065: Fix problem debugging user classes with __repr__ method.
7+
68
bpo-32631: Finish zzdummy example extension module: make menu entries
79
work; add docstrings and tests with 100% coverage.
810

Lib/idlelib/debugger_r.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
barrier, in particular frame and traceback objects.
2020
2121
"""
22-
22+
import reprlib
2323
import types
2424
from idlelib import debugger
2525

@@ -170,7 +170,7 @@ def dict_keys_list(self, did):
170170
def dict_item(self, did, key):
171171
dict = dicttable[did]
172172
value = dict[key]
173-
value = repr(value) ### can't pickle module 'builtins'
173+
value = reprlib.repr(value) ### can't pickle module 'builtins'
174174
return value
175175

176176
#----------end class IdbAdapter----------
@@ -390,4 +390,4 @@ def restart_subprocess_debugger(rpcclt):
390390

391391
if __name__ == "__main__":
392392
from unittest import main
393-
main('idlelib.idle_test.test_debugger', verbosity=2, exit=False)
393+
main('idlelib.idle_test.test_debugger_r', verbosity=2, exit=False)

Lib/idlelib/idle_test/test_debugger_r.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,19 @@ def test_init(self):
2525
# Classes GUIProxy, IdbAdapter, FrameProxy, CodeProxy, DictProxy,
2626
# GUIAdapter, IdbProxy plus 7 module functions.
2727

28+
class IdbAdapterTest(unittest.TestCase):
29+
30+
def test_dict_item_noattr(self): # Issue 33065.
31+
32+
class BinData:
33+
def __repr__(self):
34+
return self.length
35+
36+
debugger_r.dicttable[0] = {'BinData': BinData()}
37+
idb = debugger_r.IdbAdapter(None)
38+
self.assertTrue(idb.dict_item(0, 'BinData'))
39+
debugger_r.dicttable.clear()
40+
41+
2842
if __name__ == '__main__':
2943
unittest.main(verbosity=2)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix problem debugging user classes with __repr__ method.

0 commit comments

Comments
 (0)