Commit fadfaf9
committed
gh-156363: Speed up import of rlcompleter by deferring inspect and re
rlcompleter imported inspect and re at module scope, but each is used in
exactly one completion method (inspect in Completer._callable_postfix, re
in Completer.attr_matches). Neither is needed to construct a Completer or
set up interactive completion, only to compute completions.
inspect in particular is a heavy import (it pulls in dis, tokenize, ...),
so importing rlcompleter dropped from ~16.4ms to ~1.8ms of cumulative
import time on a local build. Defer both imports into the methods that use
them and add a lazy-import guard test.1 parent a728080 commit fadfaf9
3 files changed
Lines changed: 12 additions & 2 deletions
File tree
- Lib
- test
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | | - | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
| |||
105 | 103 | | |
106 | 104 | | |
107 | 105 | | |
| 106 | + | |
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
| |||
153 | 152 | | |
154 | 153 | | |
155 | 154 | | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments