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.
(cherry picked from commit 81f87bbf9f)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2021-01-09 23:30:43 -08:00 committed by GitHub
parent 9ab4dd4522
commit 799f8489d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 3 deletions

View file

@ -3,6 +3,8 @@ Released on 2020-12-07?
====================================== ======================================
bpo-33065: Fix problem debugging user classes with __repr__ method.
bpo-32631: Finish zzdummy example extension module: make menu entries bpo-32631: Finish zzdummy example extension module: make menu entries
work; add docstrings and tests with 100% coverage. work; add docstrings and tests with 100% coverage.

View file

@ -19,7 +19,7 @@ arguments and return values that cannot be transported through the RPC
barrier, in particular frame and traceback objects. barrier, in particular frame and traceback objects.
""" """
import reprlib
import types import types
from idlelib import debugger from idlelib import debugger
@ -170,7 +170,7 @@ class IdbAdapter:
def dict_item(self, did, key): def dict_item(self, did, key):
dict = dicttable[did] dict = dicttable[did]
value = dict[key] value = dict[key]
value = repr(value) ### can't pickle module 'builtins' value = reprlib.repr(value) ### can't pickle module 'builtins'
return value return value
#----------end class IdbAdapter---------- #----------end class IdbAdapter----------
@ -390,4 +390,4 @@ def restart_subprocess_debugger(rpcclt):
if __name__ == "__main__": if __name__ == "__main__":
from unittest import main from unittest import main
main('idlelib.idle_test.test_debugger', verbosity=2, exit=False) main('idlelib.idle_test.test_debugger_r', verbosity=2, exit=False)

View file

@ -25,5 +25,19 @@ class Test(unittest.TestCase):
# Classes GUIProxy, IdbAdapter, FrameProxy, CodeProxy, DictProxy, # Classes GUIProxy, IdbAdapter, FrameProxy, CodeProxy, DictProxy,
# GUIAdapter, IdbProxy plus 7 module functions. # GUIAdapter, IdbProxy plus 7 module functions.
class IdbAdapterTest(unittest.TestCase):
def test_dict_item_noattr(self): # Issue 33065.
class BinData:
def __repr__(self):
return self.length
debugger_r.dicttable[0] = {'BinData': BinData()}
idb = debugger_r.IdbAdapter(None)
self.assertTrue(idb.dict_item(0, 'BinData'))
debugger_r.dicttable.clear()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(verbosity=2) unittest.main(verbosity=2)

View file

@ -0,0 +1 @@
Fix problem debugging user classes with __repr__ method.