Skip to content

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

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

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

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. The dead self.counter
attribute was never read anywhere.

Tests

Added TestCoverageResultsInit with 3 tests verifying that counts,
calledfuncs, and callers dicts are all properly copied and not
mutated by update().

kimimgo added 2 commits March 20, 2026 00:28
…on#146044)

The unix-word-rubout command (ctrl-w) was using syntax_table-based
word boundaries (bow()), which treats punctuation as word separators.
This differs from bash/readline's unix-word-rubout which uses only
whitespace as word boundaries.

Add bow_whitespace() method that uses whitespace-only boundaries,
and use it in unix_word_rubout instead of bow(). The existing bow()
method (used by backward-kill-word/M-Backspace) is unchanged.

Example: with 'foo.bar baz' and cursor at end:
- Before (bow): ctrl-w deletes 'baz', then 'bar', then 'foo'
- After (bow_whitespace): ctrl-w deletes 'baz', then 'foo.bar'
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.

Also removes the dead self.counter attribute which was never
read anywhere in the codebase.
@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

@StanFromIreland
Copy link
Member

You have unrelated changes mixed in, can you please split them?

@kimimgo kimimgo closed this Mar 19, 2026
@kimimgo
Copy link
Author

kimimgo commented Mar 19, 2026

Closing to resubmit with clean branch — the original PR had unrelated pyrepl changes mixed in. See new PR.

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

2 participants