classification
Title: IDLE: Include keywords in __main__ autocomplete list
Type: enhancement Stage: test needed
Components: IDLE Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: cheryl.sabella, rhettinger, taleinat, terry.reedy, xtreak
Priority: normal Keywords: patch

Created on 2019-08-05 18:03 by xtreak, last changed 2019-08-10 23:24 by terry.reedy.

Pull Requests
URL Status Linked Edit
PR 15138 open terry.reedy, 2019-08-05 20:24
Messages (8)
msg349061 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-08-05 18:03
Currently, the basic repl for python provides keywords as part of autocompletion but IDLE doesn't provide them. I was trying to build an async repl on top of IDLE to support top level await statements as part of IDLE since "python -m asyncio" doesn't provide a good repl and found during usage keywords like async/await being part of autocomplete to provide a good experience like the basic repl to type faster. I couldn't find any old issues with search around why keywords were excluded so I thought of filing a new one for this suggestion.
msg349064 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-08-05 18:29
The global completion list (i.e. when not completing a file name or object attribute) is already full of all the built-ins, imported modules and variables.  So IMO we'd need a good reason to add yet more options into the completions list.

Personally, I don't think that adding all of the keywords to that list would be helpful: They are all short words and most of them must be memorized anyways to work with Python.

For instance, I don't recall this being brought up by those who often teach newcomers with IDLE, such as Raymond Hettinger, when discussing what's missing in IDLE. I'd be happy to get more input from them on this.
msg349065 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-08-05 18:30
To be clear, I'm currently -1 on this suggestion.
msg349067 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-08-05 20:16
If keywords are included when the REPL has tab completions (which Windows doesn't), then it is plausible that IDLE should.  It could be considered part of 'Shell should (mostly) imitate REPL'.  But I can see Tal's point, though the relative expansion is pretty small.  And there is nothing on the master completions issue #27609 where I collected known not-yet-rejected suggestions and ideas.

The implementation is trivial.  Add two new lines to autocomplete.py.  So you can easily patch a private copy.  I am preparing a minimal PR.

import keyword  # add
...
    def fetch_completions(self, what, mode):
...
                    bigl = eval("dir()", namespace)
                    bigl.extend(keyword.kwlist)  # add
                    bigl.sort()

True, False, and None are also in builtins, so cannot serve as a test.
---

A separate idea: annotate completion list, at least as an option, with 'keyword' or class, possibly prefixed with 'built-in', so 'built-in function', 'function', and so on.
msg349096 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-08-06 02:40
Thanks Terry, I used a similar patch. My main use case was around typing where normal shell autocompletes it and was curious if it was intentional. I didn't know that windows didn't give keywords. The keywords are short and added very rarely and perhaps the bigger completion list to actual usage might be low since no one opened this issue as Tal mentioned I am open to others feedback.
msg349362 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-08-10 22:04
After more research, I am more inclined to add the keywords to the global identifiers list. The IDLE doc says that they should be present.

"Show Completions
 Open a scrollable list allowing selection of keywords and attributes."

If this issue were rejected, the line above would have to be changed.  (Other needed updates are another issue.)  It was added to idlelib/help.txt (since replaced by help.html) by KBK in

Revision: 209de1f6ca1beaaa6b5eeb413f02e9c8c334ee50
Author: Kurt B. Kaiser <kbk@shore.net>
Date: 2/8/2007 5:58:18 PM
Message: ... Added AutoComplete instructions to IDLE Help.

(I checked 2.6 fetch_completions and keywords were not actually included in the global ('') list.)

The completion menu entry was copied to idle.rst in patches for #5066 by Jessica McKeller and Todd Rovito.  Both docs were updated.  Another 5 people, at least, reviewed, including 3 core developers.  It was committed by a 4th, Andrew Svetlov.  So 9 people besides me did not notice the discrepancy and may have thought 'keywords, fine', like I have been.

One can invoke Show Completions not following anything to get a list of names that one should not use.  For that use, keywords should be included.  This list currently has 230+ identifiers, 150+ all lowercase.  keyword.kwlist would add 32 (35 - 3 builtins).  It is not a huge increase.
msg349363 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-08-10 22:52
Since the word "main" is short and since the dunder prefix is common, I don't expect to get much value out of adding '__main__'.    ISTM, this just increases the risk of a false positive for a given dunder method.

> To be clear, I'm currently -1 on this suggestion.

I concur.
msg349365 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-08-10 23:24
Raymond, since there is no proposal to 'add __main__', I don't understand your response.  For the case in question, the completion list continues to be based on the keys in __main__.__builtins__.__dict__, and main__.__dict__, as it always has been.
History
Date User Action Args
2019-08-10 23:24:12terry.reedysetmessages: + msg349365
2019-08-10 22:52:37rhettingersetmessages: + msg349363
2019-08-10 22:04:31terry.reedysetnosy: + cheryl.sabella

messages: + msg349362
stage: patch review -> test needed
2019-08-06 02:40:12xtreaksetnosy: + rhettinger
messages: + msg349096
2019-08-05 20:37:01terry.reedylinkissue27609 dependencies
2019-08-05 20:24:22terry.reedysetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request14876
2019-08-05 20:16:06terry.reedysetnosy: - rhettinger
title: Include keywords in autocomplete list for IDLE -> IDLE: Include keywords in __main__ autocomplete list
messages: + msg349067

versions: + Python 3.7, Python 3.8
stage: test needed
2019-08-05 18:30:19taleinatsetmessages: + msg349065
2019-08-05 18:29:29taleinatsetnosy: + rhettinger
messages: + msg349064
2019-08-05 18:03:48xtreaksetnosy: + taleinat
2019-08-05 18:03:28xtreakcreate