[New-bugs-announce] [issue25419] Readline completion of module names in import statements
Martin Panter
report at bugs.python.org
Fri Oct 16 13:16:48 CEST 2015
New submission from Martin Panter:
As mentioned in Issue 25209, here is a patch to complete module and attribute names in import statements. This is a rewrite of some personal code I have had kicking around for a few years, but I have added extra features (parsing “import x as alias”, supporting “from .relative import x”).
All the existing completions should continue to work as long as the statement immediately preceding the cursor does not look like an “import” statement. When an import statement is detected, these other completions are disabled.
When alternative completions are displayed, my code appends a dot (.) indicator to package names, but this is not inserted in the input line. Maybe people think this is a good idea or maybe not.
This illustrates what it looks like in action. Text in square brackets was automatically completed:
Python 3.6.0a0 (qbase qtip readline/complete-import.patch tip:65d2b721034a, Oct 16 2015, 10:02:3)
[GCC 5.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import io, h<Tab><Tab>
hashlib heapq hmac html. http.
>>> import io, htm[l].<Tab><Tab>
html.entities html.parser
>>> import io, html.e[ntities]
>>> from html import e<Tab><Tab>
entities escape
>>> from html import es[cape]
The code works around Issue 16182 (byte vs code point indexing) in a very simplistic way. It probably won’t give useful completions (if any) for non-ASCII input involving imports.
The patch currently does not complete built-in module names (sys.builtin_module_names). This should not be hard to add, but I need to decide whether the support should be added specially in rlcompleter, or generally in pkgutil.iter_modules() instead.
I also have code to complete the following, which I could try to make patches for if there is interest:
* keyword argument names to function calls, e.g. open("file", enc[oding=]
* attributes on constructor return types, e.g. ValueError("msg").__t[raceback__]
----------
components: Library (Lib)
files: complete-import.patch
keywords: patch
messages: 253072
nosy: martin.panter, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Readline completion of module names in import statements
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file40794/complete-import.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25419>
_______________________________________
More information about the New-bugs-announce
mailing list