summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-01-10 07:30:59 (GMT)
committerGitHub <noreply@github.com>2021-01-10 07:30:59 (GMT)
commit5ded7efa6a7a232dd4a41e6e65e4dae47146514b (patch)
tree119d9e200c3f801507db83dbaec65a9429c3f66f /Lib
parentca8e96d1edbeb536f58da91e607082463398fce1 (diff)
downloadcpython-5ded7efa6a7a232dd4a41e6e65e4dae47146514b.zip
cpython-5ded7efa6a7a232dd4a41e6e65e4dae47146514b.tar.gz
cpython-5ded7efa6a7a232dd4a41e6e65e4dae47146514b.tar.bz2
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 81f87bbf9f65702062021a78abd9b8f82c98a414) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/idlelib/NEWS.txt2
-rw-r--r--Lib/idlelib/debugger_r.py6
-rw-r--r--Lib/idlelib/idle_test/test_debugger_r.py14
3 files changed, 19 insertions, 3 deletions
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index bc15501..44782fc 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,8 @@ Released on 2020-12-??
======================================
+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.
diff --git a/Lib/idlelib/debugger_r.py b/Lib/idlelib/debugger_r.py
index 9dcfc56..2620443 100644
--- a/Lib/idlelib/debugger_r.py
+++ b/Lib/idlelib/debugger_r.py
@@ -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)
diff --git a/Lib/idlelib/idle_test/test_debugger_r.py b/Lib/idlelib/idle_test/test_debugger_r.py
index 199f634..638ebd3 100644
--- a/Lib/idlelib/idle_test/test_debugger_r.py
+++ b/Lib/idlelib/idle_test/test_debugger_r.py
@@ -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)