Skip to content

Fix loop completion arcs on Python 3.14 - #2281

Merged
nedbat merged 9 commits into
coveragepy:mainfrom
HanpuLi:fix/2168-loop-completion-branch
Sep 21, 2026
Merged

nedbat merged 9 commits into
coveragepy:mainfrom
HanpuLi:fix/2168-loop-completion-branch

Conversation

@HanpuLi

@HanpuLi HanpuLi commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2168.

On Python 3.14, both settrace-based cores can receive a return event after the frame's current line has advanced without a preceding line event for that final source line. They were therefore recording the function-exit arc from the previous line, which can make normal loop exhaustion immediately before return appear as a missing branch.

For real returns on Python 3.14+, ctrace and pytrace now record that final line transition first when needed, then record the function-exit arc. Sysmon already reports the expected loop-completion arc.

The regression covers empty, exhausted, and broken-loop paths. On Python 3.14.7 the exact reproducer reports 100% branch coverage with both ctrace and pytrace after the fix; the complete tests/test_arcs.py suite also passes under both cores. A broader return/loop/try-finally probe produced identical raw arc sets for ctrace and pytrace.

PyTracer's trace callback cannot itself be measured by meta-coverage, so the new callback branch uses the repository's pragma: not covered marker. A direct PyTracer return-frame test exercises the same transition outside the trace callback, while the end-to-end arc regression verifies the real tracing behavior.

@HanpuLi

HanpuLi commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

I missed #2204 when checking for existing work on #2168. It already addresses the same CTracer/PyTracer return-arc issue, so this PR is redundant. Closing mine to avoid competing duplicate work. Sorry for the noise.

@nedbat

nedbat commented Sep 20, 2026

Copy link
Copy Markdown
Member

Thanks for the work, and for seeing the duplication, but I prefer this change. Re-opening, and making a few tweaks.

@nedbat nedbat reopened this Sep 20, 2026
@nedbat
nedbat merged commit f653aae into coveragepy:main Sep 21, 2026
79 of 102 checks passed
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.

3.14: uncovered branch for loop completion with break

2 participants