Skip to content

gh-152409: Save the trace --file counts when --no-report is used - #152410

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
tonghuaroot:cpy-trace-norep
Aug 20, 2026
Merged

gh-152409: Save the trace --file counts when --no-report is used#152410
serhiy-storchaka merged 2 commits into
python:mainfrom
tonghuaroot:cpy-trace-norep

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

python -m trace --count --no-report --file FILE now saves the counts to
FILE, so counts can be accumulated over several runs — which is what
--file and --no-report are documented to support.

The counts were pickled only at the end of
CoverageResults.write_results(), which main() skips when --no-report
is given, so --no-report --file silently discarded them. This extracts
that step into CoverageResults.save_counts() (still called from
write_results() exactly as before) and also calls it on the
--no-report branch.

save_counts() only writes when --file was given (it is a no-op
otherwise), and a --file run without --no-report already wrote the
file for every mode, so the two paths are now consistent.

The counts were only persisted at the end of CoverageResults.write_results(),
which main() skips when --no-report is given, so --no-report --file silently
discarded them.  Move that step into CoverageResults.save_counts() (still
called from write_results()) and call it on the --no-report branch too.
Comment thread Lib/trace.py Outdated

self.save_counts()

def save_counts(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes an undocumented public method of the documented public class.

Make it private.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you can keep it public and document (with versionadded).

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes and removed needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 17, 2026
@tonghuaroot

Copy link
Copy Markdown
Contributor Author

Done in 19c6975: renamed to _save_counts.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, be we need an approve of @zooko, @gvanrossum, or @smontanaro which participiated in the original discussion.

@smontanaro

Copy link
Copy Markdown
Contributor

LGTM, be we need an approve of @zooko, @gvanrossum, or @smontanaro which participiated in the original discussion.

LGTM, though given that my last involvement with the trace module was 25 years ago, I'm not sure my input means much. ;-)

@zooko

zooko commented Aug 19, 2026 via email

Copy link
Copy Markdown

@gvanrossum

Copy link
Copy Markdown
Member

Hi @serhiy-storchaka, unfortunately, like the two others, I have no recollection of how this code was supposed to work, and don't feel competent to review it now. But I trust that between you and the OP you have enough understanding to do the right thing!

@serhiy-storchaka

Copy link
Copy Markdown
Member

Sorry to bother you for such insignificant issue. I just wanted to make sure that my understanding of the original intent was correct.

@serhiy-storchaka
serhiy-storchaka merged commit 7f6389f into python:main Aug 20, 2026
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants