This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients martin.panter, serhiy.storchaka
Date 2015-10-16.11:16:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1444994208.15.0.362897114106.issue25419@psf.upfronthosting.co.za>
In-reply-to
Content
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__]
History
Date User Action Args
2015-10-16 11:16:48martin.pantersetrecipients: + martin.panter, serhiy.storchaka
2015-10-16 11:16:48martin.pantersetmessageid: <1444994208.15.0.362897114106.issue25419@psf.upfronthosting.co.za>
2015-10-16 11:16:48martin.panterlinkissue25419 messages
2015-10-16 11:16:47martin.pantercreate