Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@

import atexit
import builtins
import inspect
import keyword
import re
import __main__
import warnings
import types

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

lazy imports shouldn't be separate.

lazy import inspect
lazy import re

__all__ = ["Completer"]

# Sentinel object to distinguish "missing" from "present but None"
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import types
import rlcompleter
from test.support import MISSING_C_DOCSTRINGS
from test.support.import_helper import ensure_lazy_imports

class CompleteMe:
""" Trivial class used in testing rlcompleter.Completer. """
Expand Down Expand Up @@ -252,5 +253,9 @@ def test_duplicate_globals(self):
self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis()')
self.assertIsNone(completer.complete('Ellipsis', 1))

def test_lazy_imports(self):
ensure_lazy_imports("rlcompleter", {"inspect", "re"})


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Loading