Terry J. Reedy <tjre...@udel.edu> added the comment:

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. ***

----------
stage:  -> needs patch
title: Wrong Completion on Editing Mode of IDLE -> IDLE: Clarify some 
completion details in doc
type: behavior -> enhancement
versions: +Python 3.10 -Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41278>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to