Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Lib/test/test_tracemalloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,20 @@ def test_snapshot_group_by_cumulative(self):
tracemalloc.Statistic(tb_a_5, 2, 1),
])

def test_compare_grouped_stats_no_mutation(self):
tb_a = traceback_lineno('a.py', 1)
tb_b = traceback_lineno('b.py', 1)
old = {
tb_a: tracemalloc.Statistic(tb_a, 100, 2),
tb_b: tracemalloc.Statistic(tb_b, 50, 1),
}
new = {
tb_a: tracemalloc.Statistic(tb_a, 200, 3),
}
old_copy = dict(old)
tracemalloc._compare_grouped_stats(old, new)
self.assertEqual(old, old_copy)

def test_trace_format(self):
snapshot, snapshot2 = create_snapshots()
trace = snapshot.traces[0]
Expand Down
3 changes: 2 additions & 1 deletion Lib/tracemalloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _sort_key(self):

def _compare_grouped_stats(old_group, new_group):
statistics = []
old_group = dict(old_group)
for traceback, stat in new_group.items():
previous = old_group.pop(traceback, None)
if previous is not None:
Expand Down Expand Up @@ -478,7 +479,7 @@ def _group_by(self, key_type, cumulative):
if key_type not in ('traceback', 'filename', 'lineno'):
raise ValueError("unknown key_type: %r" % (key_type,))
if cumulative and key_type not in ('lineno', 'filename'):
raise ValueError("cumulative mode cannot by used "
raise ValueError("cumulative mode cannot be used "
"with key type %r" % key_type)

stats = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :func:`tracemalloc._compare_grouped_stats` mutating its *old_group*
argument. Also fix a typo in a :mod:`tracemalloc` error message:
"cannot by used" → "cannot be used".
Loading