[Python-checkins] bpo-33065: Fix problem debugging user classes with __repr__ method (GH-24183)
miss-islington
webhook-mailer at python.org
Sun Jan 10 02:31:11 EST 2021
https://github.com/python/cpython/commit/799f8489d418b7f9207d333eac38214931bd7dcc
commit: 799f8489d418b7f9207d333eac38214931bd7dcc
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-01-09T23:30:43-08:00
summary:
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 at udel.edu>
files:
A Misc/NEWS.d/next/IDLE/2021-01-10-01-25-43.bpo-33065.zmyHYJ.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/debugger_r.py
M Lib/idlelib/idle_test/test_debugger_r.py
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index c466fe9cc7776..0033e66f9b8a2 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -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
work; add docstrings and tests with 100% coverage.
diff --git a/Lib/idlelib/debugger_r.py b/Lib/idlelib/debugger_r.py
index 9dcfc56414c05..26204438858d8 100644
--- a/Lib/idlelib/debugger_r.py
+++ b/Lib/idlelib/debugger_r.py
@@ -19,7 +19,7 @@
barrier, in particular frame and traceback objects.
"""
-
+import reprlib
import types
from idlelib import debugger
@@ -170,7 +170,7 @@ def dict_keys_list(self, did):
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 199f63447ce6c..638ebd36a7405 100644
--- a/Lib/idlelib/idle_test/test_debugger_r.py
+++ b/Lib/idlelib/idle_test/test_debugger_r.py
@@ -25,5 +25,19 @@ def test_init(self):
# 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
index 0000000000000..87948f3cd1baa
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2021-01-10-01-25-43.bpo-33065.zmyHYJ.rst
@@ -0,0 +1 @@
+Fix problem debugging user classes with __repr__ method.
More information about the Python-checkins
mailing list