{{ message }}
gh-117865: Speedup import of inspect module#144756
Merged
hugovk merged 8 commits intoMar 2, 2026
Merged
Conversation
While we can easily make ast import lazy in inspect module, it is anyway imported in annotationlib, which cannot be made lazy.
danielhollas
commented
Feb 12, 2026
This was referenced Feb 12, 2026
JelleZijlstra
approved these changes
Feb 13, 2026
JelleZijlstra
left a comment
Member
There was a problem hiding this comment.
Makes sense. re is used only in one place in formatannotation, so many users won't need it. tokenize is used a bit more heavily but most of the API in the module still won't need it.
Sorry, something went wrong.
hugovk
approved these changes
Feb 19, 2026
Contributor
Author
|
Hi all, just a kind ping to see if this PR could be merged. 😊 |
Sorry, something went wrong.
Hide details
View details
hugovk
merged commit
ea90b03
into
python:main
Mar 2, 2026
85 of 87 checks passed
ljfp
pushed a commit
to ljfp/cpython
that referenced
this pull request
Apr 25, 2026
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
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
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.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.
This is a revived version of #119526 (with Alex's blessing), using the new fancy lazy import machinery to defer imports of
reandtokenizemodules, for a ~20% speedup.Before
After
Part of #137855