Skip to content
Open
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
1 change: 1 addition & 0 deletions Lib/pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def load_stats(self, arg):
except: # in case this is not unix
pass
self.files = [arg]
return
elif hasattr(arg, 'create_stats'):
arg.create_stats()
self.stats = arg.stats
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def test_add(self):
stats = pstats.Stats(stream=stream)
stats.add(self.stats, self.stats)

def test_empty_stats(self):
# gh-109500: Empty profiling data must not prevent loading or
# combining statistics.
stats_file = support.findfile('pstats.pck')
profile = cProfile.Profile()
with tempfile.TemporaryDirectory() as tmpdir:
filename = os.path.join(tmpdir, 'empty.prof')
profile.dump_stats(filename)
self.assertEqual(pstats.Stats(profile, filename).stats, {})
stats = pstats.Stats(filename, stats_file)
self.assertEqual(stats.stats, self.stats.stats)

def test_dump_and_load_works_correctly(self):
temp_storage_new = tempfile.NamedTemporaryFile(delete=False)
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :class:`pstats.Stats` and :meth:`pstats.Stats.add` raising
:exc:`TypeError` when loading files containing empty profiling data.
Loading