FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-156363: Speed up import of rlcompleter by deferring inspect and re by maxday · Pull Request #156364 · python/cpython · GitHub

/ cpython Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions Lib/rlcompleter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
Comment on lines +1 to +5

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
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

Back | FazBrowse Home | New Git URL