| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…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.
|
I believe the macOS failing test can be rerun, looks like it's a network error issue, from the log: "The hosted runner lost communication with the server. Anything in your workflow that terminates the runner process, starves it for CPU/Memory, or blocks its network access can cause this error." |
Sorry, something went wrong.
|
If we decide to do this, we can use the lazy import syntax introduced in https://peps.python.org/pep-0810/ to resolve it. |
Sorry, something went wrong.
|
|
||
| def _callable_postfix(self, val, word): | ||
| if callable(val): | ||
| import inspect |
There was a problem hiding this comment.
Rather than deferring both these imports, let's use the new lazy keyword and keep them at the top. List the lazy imports after the regular imports.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
…pleter Address review feedback: replace deferred in-function imports of `inspect` and `re` with `lazy import` statements at the top of the module, keeping them alongside the regular imports.
| import __main__ | ||
| import warnings | ||
| import types | ||
|
|
There was a problem hiding this comment.
lazy imports shouldn't be separate.
Sorry, something went wrong.
| Speed up ``import rlcompleter`` by deferring the imports of :mod:`inspect` | ||
| and :mod:`re` into the completion methods that use them. They are only | ||
| needed while computing completions, so importing :mod:`rlcompleter` (for | ||
| example when setting up interactive completion) no longer pays their import | ||
| cost. |
There was a problem hiding this comment.
| Speed up ``import rlcompleter`` by deferring the imports of :mod:`inspect` | |
| and :mod:`re` into the completion methods that use them. They are only | |
| needed while computing completions, so importing :mod:`rlcompleter` (for | |
| example when setting up interactive completion) no longer pays their import | |
| cost. | |
| Speed up the :mod:`rlcompleter` module's import time. |
The rest is implementation details.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Speed up import of rlcompleter by deferring inspect and re
Defer the imports of inspect and re in rlcompleter into the methods that actually use them (_callable_postfix and attr_matches).
Impact
On a local build, importing rlcompleter dropped from ~16.4 ms to ~1.8 ms of cumulative import time.
Measured with:
Test
A regression test using test.support.import_helper.ensure_lazy_imports guards that inspect and re are not imported as a side effect of importing rlcompleter.
Fixes: #156363