Skip to content

Speed up import rlcompleter by deferring inspect and re #156363

Description

@maxday

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions