Skip to content

gh-145865: Fix CoverageResults.__init__ to copy the counts dict#146183

Open
kimimgo wants to merge 2 commits intopython:mainfrom
kimimgo:fix/trace-counts-copy-145865-clean
Open

gh-145865: Fix CoverageResults.__init__ to copy the counts dict#146183
kimimgo wants to merge 2 commits intopython:mainfrom
kimimgo:fix/trace-counts-copy-145865-clean

Conversation

@kimimgo
Copy link

@kimimgo kimimgo commented Mar 19, 2026

Fixes #145865

Summary

CoverageResults.__init__ had a typo on line 158:

self.counter = self.counts.copy()  # typo: creates dead attribute

should be:

self.counts = self.counts.copy()  # matches calledfuncs/callers pattern

This caused self.counts to be an alias to the caller's dict, so
update() would mutate the original dict.

Tests

Added TestCoverageResultsInit with 3 tests verifying that counts,
calledfuncs, and callers dicts are all properly copied.

Changes from previous PR #146176

Removed unrelated pyrepl changes that were accidentally included.

Fix typo where self.counter was assigned instead of self.counts,
causing the counts dict to not be copied. This made
CoverageResults.update() mutate the caller's original dict.

The fix changes self.counter = self.counts.copy() to
self.counts = self.counts.copy(), matching the pattern used
for calledfuncs and callers on the following lines.
@bedevere-app
Copy link

bedevere-app bot commented Mar 19, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented Mar 19, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

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.

trace.CoverageResults.__init__ does not copy the counts dict

1 participant