Skip to content

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

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:cpy-trace-norep
Open

gh-152409: Save the trace --file counts when --no-report is used#152410
tonghuaroot wants to merge 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants