]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33065: Fix problem debugging user classes with __repr__ method (GH-24183)
authorTerry Jan Reedy <tjreedy@udel.edu>
Sun, 10 Jan 2021 06:59:47 +0000 (01:59 -0500)
committerGitHub <noreply@github.com>
Sun, 10 Jan 2021 06:59:47 +0000 (01:59 -0500)
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.

Lib/idlelib/NEWS.txt
Lib/idlelib/debugger_r.py
Lib/idlelib/idle_test/test_debugger_r.py
Misc/NEWS.d/next/IDLE/2021-01-10-01-25-43.bpo-33065.zmyHYJ.rst [new file with mode: 0644]

index b04ea7493477eae5faa96d558e1d005424d85915..26200981eb8d93494c7e2dcc369640cda6058732 100644 (file)
@@ -3,6 +3,8 @@ Released on 2021-10-04?
 ======================================
 
 
+bpo-33065: Fix problem debugging user classes with __repr__ method.
+
 bpo-32631: Finish zzdummy example extension module: make menu entries
 work; add docstrings and tests with 100% coverage.
 
index 9dcfc56414c05059c3d89b68d634d23dcbb16fee..26204438858d8a4b8e3850c5e8276b7208448b2f 100644 (file)
@@ -19,7 +19,7 @@ arguments and return values that cannot be transported through the RPC
 barrier, in particular frame and traceback objects.
 
 """
-
+import reprlib
 import types
 from idlelib import debugger
 
@@ -170,7 +170,7 @@ class IdbAdapter:
     def dict_item(self, did, key):
         dict = dicttable[did]
         value = dict[key]
-        value = repr(value) ### can't pickle module 'builtins'
+        value = reprlib.repr(value) ### can't pickle module 'builtins'
         return value
 
 #----------end class IdbAdapter----------
@@ -390,4 +390,4 @@ def restart_subprocess_debugger(rpcclt):
 
 if __name__ == "__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)
index 199f63447ce6cac9135c31a80e3b39e650a713b7..638ebd36a7405d273105dcc36d474b8746cede4c 100644 (file)
@@ -25,5 +25,19 @@ class Test(unittest.TestCase):
 # Classes GUIProxy, IdbAdapter, FrameProxy, CodeProxy, DictProxy,
 # 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__':
     unittest.main(verbosity=2)
diff --git a/Misc/NEWS.d/next/IDLE/2021-01-10-01-25-43.bpo-33065.zmyHYJ.rst b/Misc/NEWS.d/next/IDLE/2021-01-10-01-25-43.bpo-33065.zmyHYJ.rst
new file mode 100644 (file)
index 0000000..87948f3
--- /dev/null
@@ -0,0 +1 @@
+Fix problem debugging user classes with __repr__ method.