python / python/cpython

Speed up import rlcompleter by deferring inspect and re

Open
#156,363 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

rlcompleter imports inspect and re at module scope, but neither is needed to import the module or to construct a Completer. Each is used in exactly one completion method:

  • inspect: only in Completer._callable_postfix
  • re: only in Completer.attr_matches

inspect in particular is a heavy import: it transitively pulls in dis, tokenize, and more. Because rlcompleter is imported during interactive startup (to set up tab completion via readline), this import cost is paid on every interactive session and every import rlcompleter, even though the completion methods may never run.

Linked PRs
  • gh-156364

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the rlcompleter module and the Completer._callable_postfix and Completer.attr_matches entry points named in the issue. Verify the import behavior before and after the change, and confirm that completion behavior remains correct while importing rlcompleter no longer pays for unused dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, developer-experience
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.