gh-117865: Speedup import of inspect module#144756
gh-117865: Speedup import of inspect module#144756danielhollas wants to merge 8 commits intopython:mainfrom
inspect module#144756Conversation
While we can easily make ast import lazy in inspect module, it is anyway imported in annotationlib, which cannot be made lazy.
Lib/inspect.py
Outdated
| from weakref import ref as make_weakref | ||
| from _weakref import ref as make_weakref | ||
|
|
||
| lazy import re |
There was a problem hiding this comment.
Not sure about the convention here: where do we put lazy imports?
There was a problem hiding this comment.
My intuition would be that you put them in the same place you'd have put them before, just with "lazy" in front.
(Yay, a new thing to argue about! I guess isort will have to make the decision for us in the future.)
There was a problem hiding this comment.
Thanks, yeah I put them back, it also made the diff nicer. (currently there doesn't seem to be consistent sorting in stdlib anyway)
JelleZijlstra
left a comment
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.
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