https://github.com/python/cpython/commit/72b3e374a32989a07bbab057695942b2cc23a294
commit: 72b3e374a32989a07bbab057695942b2cc23a294
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-05T00:57:54+01:00
summary:
gh-141510: Add frozendict support to python-gdb.py (#145511)
files:
M Lib/test/test_gdb/test_pretty_print.py
M Tools/gdb/libpython.py
diff --git a/Lib/test/test_gdb/test_pretty_print.py
b/Lib/test/test_gdb/test_pretty_print.py
index dfc77d65ab16a4..db3064e3df54c2 100644
--- a/Lib/test/test_gdb/test_pretty_print.py
+++ b/Lib/test/test_gdb/test_pretty_print.py
@@ -82,7 +82,14 @@ def test_dicts(self):
self.assertGdbRepr({})
self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}")
# Python preserves insertion order since 3.6
- self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'foo': 'bar',
'douglas': 42}")
+ self.assertGdbRepr({'foo': 'bar', 'douglas': 42},
+ "{'foo': 'bar', 'douglas': 42}")
+
+ # frozendict
+ self.assertGdbRepr(frozendict(),
+ "frozendict({})")
+ self.assertGdbRepr(frozendict({'foo': 'bar', 'douglas': 42}),
+ "frozendict({'foo': 'bar', 'douglas': 42})")
def test_lists(self):
'Verify the pretty-printing of lists'
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
index a85195dcd1016a..ba52ea2a30e0be 100755
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -352,6 +352,7 @@ def subclass_from_type(cls, t):
'frame': PyFrameObjectPtr,
'set' : PySetObjectPtr,
'frozenset' : PySetObjectPtr,
+ 'frozendict' : PyDictObjectPtr,
'builtin_function_or_method' : PyCFunctionObjectPtr,
'method-wrapper': wrapperobject,
}
@@ -815,12 +816,20 @@ def proxyval(self, visited):
return result
def write_repr(self, out, visited):
+ tp_name = self.safe_tp_name()
+ is_frozendict = (tp_name == "frozendict")
+
# Guard against infinite loops:
if self.as_address() in visited:
- out.write('{...}')
+ if is_frozendict:
+ out.write(tp_name + '({...})')
+ else:
+ out.write('{...}')
return
visited.add(self.as_address())
+ if is_frozendict:
+ out.write(tp_name + '(')
out.write('{')
first = True
for pyop_key, pyop_value in self.iteritems():
@@ -831,6 +840,8 @@ def write_repr(self, out, visited):
out.write(': ')
pyop_value.write_repr(out, visited)
out.write('}')
+ if is_frozendict:
+ out.write(')')
@staticmethod
def _get_entries(keys):
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]