GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-80642: Correct the documented default for `Timer.autorange`'s `target_time` by Dhairya-007 · Pull Request #161509 · python/cpython

Conversation

@Dhairya-007

@Dhairya-007 Dhairya-007 commented Nov 6, 2026

Copy link
Copy Markdown

Doc/library/timeit.rst documents the signature as:

.. method:: Timer.autorange(callback=None, target_time=None)

but the parameter does not default to None:

# Lib/timeit.py
default_target_time = 0.2
...
    def autorange(self, callback=None, target_time=default_target_time):

None is not a usable value either — autorange does if time_taken >= target_time, which raises TypeError when compared against None. So a reader following the documented signature and passing target_time=None explicitly gets a crash rather than the default behaviour.

The parameter is new in 3.15 (added in gh-80642 / GH-140283), so this has not been wrong for long.

I used the concrete value rather than the constant name to match the neighbouring entries in the same file, which already do this:

.. method:: Timer.timeit(number=1000000)
.. method:: Timer.repeat(repeat=5, number=1000000)

rather than naming default_number and default_repeat.

Note on GH-144825

GH-144825 also edits this directive, but only rewords the description body; it leaves the signature line unchanged, so there is no overlap with this one-line change. That PR does incidentally drop the stray *Timer.target_time* reference on the following line (there is no such attribute — it should be *target_time*), so I have deliberately left that alone here to avoid conflicting with it.

Documentation only, so no NEWS entry.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Dhairya-007
Docs: correct the documented default for Timer.autorange's target_time
e8d8de9
The signature documented target_time=None, but the parameter defaults to
default_target_time, which is 0.2. None is not a usable value: autorange
compares time_taken >= target_time, which raises TypeError against None.

Uses the concrete value, matching the neighbouring Timer.timeit and
Timer.repeat entries, which document number=1000000 and repeat=5 rather
than the default_number and default_repeat constants.
@bedevere-app bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Nov 6, 2026
@github-project-automation github-project-automation Bot added this to Docs PRs Nov 6, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Nov 6, 2026
@read-the-docs-community

read-the-docs-community Bot commented Nov 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35738952 | 📁 Comparing cf5fe29 against main (2781ffe)

  🔍 Preview build  

50 files changed · ± 50 modified

± Modified

  • builtins/functions.html
  • c-api/module.html
  • c-api/typeobj.html
  • extending/embedding.html
  • extending/extending.html
  • howto/descriptor.html
  • howto/instrumentation.html
  • howto/isolating-extensions.html
  • howto/logging-cookbook.html
  • library/annotationlib.html
  • and 40 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz added the skip issue label Nov 8, 2026
@picnixz picnixz changed the title Docs: correct the documented default for Timer.autorange's target_time Correct the documented default for Timer.autorange's target_time Nov 8, 2026
@picnixz picnixz added the needs backport to 3.15 bugs and security fixes label Nov 8, 2026
@picnixz picnixz changed the title Correct the documented default for Timer.autorange's target_time gh-80642: Correct the documented default for Timer.autorange's target_time Nov 8, 2026
@picnixz picnixz removed the skip issue label Nov 8, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 8, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 8, 2026
timeit: Additional changes for autorange #80642
Closed
picnixz
picnixz approved these changes Nov 8, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Nov 8, 2026
picnixz
picnixz reviewed Nov 8, 2026
View reviewed changes
Comment thread Doc/library/timeit.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Dhairya-007
Drop the nonexistent Timer.target_time reference
cf5fe29
Timer has no target_time attribute: target_time is a parameter of
autorange(), defaulting to the module-level default_target_time. The next
sentence already refers to it as *target_time*.
@Dhairya-007

Dhairya-007 commented Nov 8, 2026

Copy link
Copy Markdown
Author

Good catch — it doesn't exist. Timer has no target_time attribute; target_time is only a parameter of autorange(), defaulting to the module-level default_target_time (0.2). Dropped the Timer. prefix in cf5fe29, which also makes it consistent with the *target_time* two lines below.

Worth noting there is some overlap with #144825, which rewords this same paragraph (and happens to drop that line altogether). Happy to defer to it if you'd rather land that one first — this PR is just the target_time=0.2 default in the signature, which that PR doesn't change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 8, 2026

Copy link
Copy Markdown
Member

We can first fix the typo and see what to do with the other PR later.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@picnixz picnixz picnixz approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting merge docs Documentation in the Doc dir needs backport to 3.15 bugs and security fixes skip news type-feature A feature request or enhancement

Projects

Docs PRs
Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Dhairya-007 @picnixz
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.