#109500·Python

pstats's Stats object cannot be created from multiple data sources if some are empty.

Author: thisismypassportCreated Sep 16, 2023Updated Sep 28, 2026
Labelstype-bug

Bug report

Bug description:

Current Behavior: pstats.Stats(*args) fails if even one of the args refers to empty profiling data

Expected Behavior: pstats.Stats(*args) should not fail if some of the args refer to empty profiling data, since the end result would've been a non-empty stats object.

Rationale: pstats.Stats(*args) may be used to aggregate stats from multiple places, and some of them may happen to be empty. Aside: In fact, due to that, I'm not sure pstats.Stats(*args) should fail even if it ends up wholly empty, as it already supports an empty state (pstats.Stats()) that it could use instead.

Reproducible Example (2 variants):

python
import cProfile, pstats

pa = cProfile.Profile()
pa.enable()
pa.disable()

pb = cProfile.Profile()
if True:
    # bug variant 1:
    stats = pstats.Stats(pa,pb) # TypeError
else:
    # bug variant 2:
    pb.dump_stats("some_file") # OK
    stats = pstats.Stats(pa,"some_file") # TypeError

CPython versions tested on:

3.11

Operating systems tested on:

Windows

Linked PRs

  • gh-158363