Title: IDLE: Clarify some completion details in doc
Type: enhancement Stage: needs patch
Components: IDLE Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Alex-Python-Programmer, epaine, terry.reedy
Priority: normal Keywords:

Created on 2020-07-11 07:12 by Alex-Python-Programmer, last changed 2020-07-16 04:33 by Alex-Python-Programmer.

Messages (8)
msg373518 - (view) Author: Alex (Alex-Python-Programmer) Date: 2020-07-11 07:12
When I type (on editing mode, not interacting mode) __main__. + Ctrl+Space, the completion window shows 'idlelib'.
msg373524 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-11 13:37
On Windows, with 3.8.4rc1 and 3.8 repository, ^space brings up proper list.  Give more details.
msg373625 - (view) Author: Alex (Alex-Python-Programmer) Date: 2020-07-14 06:48
Well. I found that this bug happens frequntly, sometimes it just shows the proper list, like __builtins__, __docs__ and stuff. Sometimes the completion windows just gives me 'idlelib'.
p.s.:idle won't show __main__ when you type something and press ctrl+space, but the completion *seems do* exist (and gives the proper list that I said before) when you type ctrl+space, but by pressing enter a NameError is raised because __main__ *do not* exist, actually. I'm finding out why this happens, and when.
p.p.s:I'm using python 3.8.2 shell.
msg373635 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-14 13:32
We cannot do anything with this report unless you give exact keystroke-by-keystroke details and we are able to reproduce the issue.  Also, what OS?  If *nix, which?  How did you start IDLE?

Unless you start IDLE with -n or explicitly import idlelib, it should not be possible for idlelib to appear as a completion.  The code was written to avoid adding anything to the main namespace.  When you start or restart Shell, dir() only lists double underscore names.
msg373638 - (view) Author: E. Paine (epaine) * Date: 2020-07-14 15:02
I can only seem to reproduce this in shell and that is by importing "idlelib.__main__" before then typing "__main__."

However, typing "__main__." in shell and editor (without importing "idlelib.__main__") does give different completions. In shell, it gives a list of the usual "__annotations__", "__builtins__", etc. However, in editor (run from the home directory without any command-line flags), the only completion is "main" (note: the shell must be closed, otherwise it will give the same completions as the shell)
msg373662 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-07-14 23:14
Although a few keystrokes are omitted, I reproduced the examples and can explain the results by elaborating on my claims above.

0. Python starts execution in module '__main__', which initially contains only double underscore names (now 7).

1. If a module name is not in the user code main namespace, IDLE checks in sys.modules, which initially contains '__main__' and many others.

2. 'fetch_completions' returns two completion lists: big, with all appropriate names, and small, without underscore names.  If big is not empty, the initial display is small if not empty, else big. 

Hence, at startup, '__main__.' displays the big list with 7 dunder names because small is empty.  Assign to *any* 'normal' name, so that small contains 1 name, and '__main__.' initially displays that 1 name.  There is nothing special about 'idlelib' here.

The above is true when editing.

3. When there is no Shell, there is no user process, the same as if one started IDLE with -n to never have a separate user process.  When there is no user process, completions are done in the IDLE GUI process, and its main module contains 'idlelib' from IDLE's startup imports.  So the small completion list contains 'idlelib'.

For '__main__.x' to run, there must be a previous 'import __main__'.  If one runs the editor code after entering import statements, as the doc recommends, a user process will be started.

*** I just edited the IDLE completion doc, but 1, 2, and 3 could be made clearer.  I am leaving this issue open to do so. ***
msg373674 - (view) Author: E. Paine (epaine) * Date: 2020-07-15 09:33
Terry, can we change the user process to be owned by the filelist rather than the shell to avoid this difference in behaviour? (I can't think of any reason off the top of my head of why this couldn't happen)
msg373740 - (view) Author: Alex (Alex-Python-Programmer) Date: 2020-07-16 04:33
new feature found: 
1.although the name __main__ do not exist even when editing, there will be some completions.
2.if you run a module like this:
def new():
then create a new module, press __main__. + tab. it will become
3.but, if you press __main__._ + tab, the proper list and new will both be shown.
4.the feature 2 & 3 appears even if the first module is closed.
Date User Action Args
2020-07-16 04:33:16Alex-Python-Programmersetmessages: + msg373740
2020-07-15 09:33:11epainesetmessages: + msg373674
2020-07-14 23:14:00terry.reedysetversions: + Python 3.10, - Python 3.8
title: Wrong Completion on Editing Mode of IDLE -> IDLE: Clarify some completion details in doc
messages: + msg373662

type: behavior -> enhancement
stage: needs patch
2020-07-14 15:02:31epainesetnosy: + epaine
messages: + msg373638
2020-07-14 13:32:33terry.reedysetstatus: pending -> open

messages: + msg373635
2020-07-14 06:48:31Alex-Python-Programmersetstatus: open -> pending

messages: + msg373625
2020-07-11 13:37:02terry.reedysetmessages: + msg373524
2020-07-11 07:12:44Alex-Python-Programmercreate