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.

classification
Title: IDLE: Add import statement completion
Type: enhancement Stage: needs patch
Components: IDLE Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ramchandra Apte, martin.panter, roger.serwy, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2013-02-19 15:32 by Ramchandra Apte, last changed 2022-04-11 14:57 by admin.

Messages (8)
msg182392 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013-02-19 15:32
[patch under development]
I propose to add completions for 
import <tab>
from <tab>
from x import <tab>

Also, if one types imp.<tab> , IDLE should import the module and list dir(module).
(There will be an option to disable/enable the last two completion cases as some users object to it importing modules for completion)
msg191227 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-06-15 19:22
Making a list of all possible modules is harder than a list of attributes. With relative imports, I am not sure its even possible to sensible make a list of every entry that would work.
msg191260 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013-06-16 05:06
I have a patch ready; have to make it ready (PEP8-compliance etc.) and then
I can send it.

On 16 June 2013 00:52, Terry J. Reedy <report@bugs.python.org> wrote:

>
> Terry J. Reedy added the comment:
>
> Making a list of all possible modules is harder than a list of attributes.
> With relative imports, I am not sure its even possible to sensible make a
> list of every entry that would work.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue17238>
> _______________________________________
>
msg271199 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-07-25 01:23
Even if your patch isn’t quite ready, it may (have been) better than nothing :)

I had the idea to share stuff between Idle completion and Readline completion, but after looking at the Idle code, it did not seem very practical in general. But maybe you can at least use some ideas, test cases, or share the low level code from Issue 25419. E.g. my patch there has method _import_matches() that takes a path of packages and yields (sub)module names, and method _from_import_matches() that also yields module attribute names.
msg271216 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-07-25 02:51
I change 'enhance' to 'add' because there is no 'import completion' now.

Ramchandra, when replying by email, delete the quoted email.  But do submit a patch even is less than perfect.

The idea of autoimporting a name to complete an attribute is separate from the idea of doing something special in import statements.  Autoimport is the subject of #18766, which has a patch and my thoughts so far.  So this issue is only about import statements.

Martin, I just opened #27609 as an umbrella issue for multiple completion issues.  I am not happy with the current IDLE completion code.  Does any of the readline completion code depend on function provided by readline, or is it all an extension of readline, using logic in Python?
msg271348 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-07-26 08:53
The readline completion code does not strictly depend on on Readline, although currently it is modelled after its quirky API. But we can change that by adding a more general API.

In <https://bugs.python.org/issue25419#msg266320>, I suggested an API “complete_code(code) -> list of modules, attributes, globals, etc.” In the Readline case, you pass in the line of code up to the cursor, and it would return possible completions. Perhaps Idle might pass in multiple lines of code. There could also be a predefined global namespace, either as another parameter, or preloaded into a completer object.

When I briefly looked at the Idle code a while back, it did not seem easy for me to adapt to this sort of API. But maybe you have a better idea of what could be done.
msg370848 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-06-06 19:31
I opened #40892 for using rlcomplete suffixes.
I should look as #25419 for patch and messages for import ideas.
msg373246 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-07 20:31
+1 for import completion.  Above, I misspelled 'rlcompleter' as 'rlcomplete'.  When I just tried to import it as part of responding to #41230, the wrong name did not work.  I wish I could have stopped with 'import rl'<tab>.  To add a note to #37765, I tried 'import keywords'.  Nope, no 's'.  'import ke'<tab> would have been nice.  I suspect that some beginners have as much trouble with names they have no recently used.

im<tab> would work if keywords were added to the tab completion list. #37765.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61440
2020-07-07 20:31:48terry.reedysetmessages: + msg373246
2020-06-07 21:59:21terry.reedysetversions: + Python 3.10, - Python 3.6
2020-06-06 19:31:51terry.reedysetmessages: + msg370848
2016-07-26 08:53:30martin.pantersetmessages: + msg271348
2016-07-25 02:51:20terry.reedysettitle: IDLE: Enhance import statement completion -> IDLE: Add import statement completion
messages: + msg271216
versions: + Python 3.6, - Python 3.4
2016-07-25 01:23:33martin.pantersetnosy: + martin.panter
messages: + msg271199
2016-07-25 00:08:07terry.reedylinkissue27609 dependencies
2013-06-17 20:35:11serhiy.storchakasetnosy: + serhiy.storchaka
2013-06-16 05:06:35Ramchandra Aptesetmessages: + msg191260
2013-06-15 19:22:40terry.reedysetmessages: + msg191227
2013-04-07 01:36:20roger.serwysetnosy: + roger.serwy

title: Enhance import statement completion -> IDLE: Enhance import statement completion
2013-02-19 15:35:51ezio.melottisetstage: needs patch
versions: - Python 3.3
2013-02-19 15:32:51Ramchandra Aptecreate