Repository navigation
Conversation
The docs and CLI help said setup ran "once initially" or "only once at the beginning". Setup actually runs once at the start of every Timer.timeit() call, so repeat(), autorange(), and the command-line interface run it more than once. Assisted-by: Grok Bot
|
📖 2 files modified Preview · build overview · cpython-previews · built Dec. 1, 2026, 5:48 p.m. UTC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The timeit docs said the setup statement "is executed only once at the beginning", and the
-s/--setuphelp said it was "executed once initially". That doesn't match the code.Timer.timeit()runs setup once, then times the statement. That part is right. Butrepeat()andautorange()calltimeit()again for each trial, and the command-line tool uses both (autorange when-nis omitted, thenrepeatwith a default of 5). So setup usually runs many times, not once at the start. That is why this check fails:import csvfrom an earlier trial is already insys.moduleswhen setup runs again.This updates:
Doc/library/timeit.rst: theTimerclass, thetimeit()method, the-soption, and the examples intro, so they describe the actual once-per-call behaviorTimer.timeitdocstring and the argparse help inLib/timeit.pyNo runtime behavior is changed.
Fixes #114665
I confirmed the old wording against the current
timeit()/repeat()/autorange()/ CLI code, ran./python -m test test_timeit(44 tests, OK), and builtDoc/library/timeit.rstwith Sphinx. The new sentences show up in the HTML, and the only Sphinx warnings were from other pages that were not part of this partial docs build.AI assistance: I used an AI coding agent to find the misleading wording, draft the edits, and run the tests and docs build. I reviewed the diff and checked it against the implementation.