[3.14] gh-134235: Import Autocomplete for Builtin Modules (GH-134277) (#134285)

gh-134235: Import Autocomplete for Builtin Modules (GH-134277)

* added enhancement auto completing import with sys builtins

---------
(cherry picked from commit 8421b03b16)

Co-authored-by: Tom Wang <85062819+tommix626@users.noreply.github.com>
Co-authored-by: Hunter <hyoung3@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-05-19 23:46:50 +02:00 committed by GitHub
parent 7686c752b3
commit 7cbc3ea8fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View file

@ -81,8 +81,9 @@ def find_modules(self, path: str, prefix: str) -> list[str]:
def _find_modules(self, path: str, prefix: str) -> list[str]:
if not path:
# Top-level import (e.g. `import foo<tab>`` or `from foo<tab>`)`
return [name for _, name, _ in self.global_cache
if name.startswith(prefix)]
builtin_modules = [name for name in sys.builtin_module_names if name.startswith(prefix)]
third_party_modules = [name for _, name, _ in self.global_cache if name.startswith(prefix)]
return sorted(builtin_modules + third_party_modules)
if path.startswith('.'):
# Convert relative path to absolute path