FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-141510: Add frozendict support to python-gdb.py by vstinner · Pull Request #145511 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 8 additions & 1 deletion Lib/test/test_gdb/test_pretty_print.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 12 additions & 1 deletion Tools/gdb/libpython.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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():
Expand All @@ -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):
Expand Down
Loading

Back | FazBrowse Home | New Git URL