8000 Auto-complete modules for `import` and `from` statements in REPL · Issue #117312 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
beavailable opened this issue Mar 28, 2024 · 2 comments
Closed

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

beavailable opened this issue Mar 28, 2024 · 2 comments
Labels
type-feature A feature request or enhancement

Comments

@beavailable
Copy link
Contributor
beavailable commented Mar 28, 2024

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

@beavailable beavailable added the type-feature A feature request or enhancement label Mar 28, 2024
@serhiy-storchaka
Copy link
Member

It looks like a duplicate of #69605.

@beavailable
Copy link
Contributor Author

OK, I'll close this one.

@beavailable beavailable closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants
0