Skip to content

Auto-complete modules for import and from statements in REPL #117312

Closed as not planned
@beavailable

Description

@beavailable

Feature or enhancement

Proposal:

I have wrote some code to auto-complete modules for import and from statements in REPL.
It's simple, so it can't auto-complete after from ... import, and it's only available when readline is available, but is better than nothing.

Here is the output of diff command (compared to version 3.11.2):

37a38,39
> import sys
> import pkgutil
94c96,103
<                 self.matches = self.global_matches(text)
---
>                 if _readline_available:
>                     start = readline.get_line_buffer()[:readline.get_begidx()]
>                     if re.fullmatch(r'(import|from)\s+', start):
>                         self.matches = self.module_matches(text)
>                     else:
>                         self.matches = self.global_matches(text)
>                 else:
>                     self.matches = self.global_matches(text)
200a210,220
> 
>     def module_matches(self, text):
>         matches = []
>         for name in sys.builtin_module_names:
>             if name.startswith(text):
>                 matches.append(name)
>         for modinfo in pkgutil.iter_modules():
>             if modinfo.name.startswith(text):
>                 matches.append(modinfo.name)
>         return matches
>

I'm thinking that if it's OK to merge these code into the official repo, if it is, please let me know.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions