Issue: 92359 - Python 3.10 IDLE 64-bit doesn't open any files names code (code.py, code.pyw) - found a partial fix but looking for input

Hello, Link to the github issue page is here https://github.com/python/cpython/issues/92359 This bug has been lurking in waiting for roughly 7 years or possibly longer. The root issue is that the "Edit with IDLE" context menu executes idle with `python.exe -m idlelib` which puts the current working directory in sys.path but inside idlelib it has a `from code import ...` statement. A kind of ugly hack is sitting in my fork of cpython here https://github.com/devdave/cpython/blob/issue_92359/Lib/idlelib/__main__.py . All I did was put the Lib directory at the front of sys.path. Perhaps this is the best solution? I don't know. Would appreciate any ideas for an alternative fix (ex perhaps changing how "Edit with IDLE" works?) or like I said, perhaps my fix is the best option because of how simple it is? Thanks, DevDave

On 5/13/2022 9:20 PM, ward.davidj@gmail.com wrote:
This is a specific (and now closed) example of import shadowing. The general issue is the subject of https://github.com/python/cpython/issues/67997 -- Terry Jan Reedy

So the "current working directory" is the directory containing the file, right? That would explain the behavior. Probably "Edit with IDLE" should be changed. I have no idea where that is defined. In 3.11 we should be able to make that use the new -P option, which doesn't insert the working directory at the front of sys.path. On Fri, May 13, 2022 at 6:50 PM <ward.davidj@gmail.com> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

On 5/14/2022 12:40 AM, Guido van Rossum wrote:
So the "current working directory" is the directory containing the file, right? That would explain the behavior.
Standard import shadowing.
Probably "Edit with IDLE" should be changed. I have no idea where that is defined.
I presume somewhere in PCBuild. Steve Dower knows and is in charge of the Windows installer.
In 3.11 we should be able to make that use the new -P option, which doesn't insert the working directory at the front of sys.path.
This would only solve the issue for that one of many ways to start IDLE. Example: Entering command 'py -m idlelib', with or without the name of the file added, in a directory with a shadow module. Traceback... ImportError: cannot import name 'InteractiveInterpreter' from 'code' (F:\dev\tem\code.py) The difference is that the import exception is printed: (Yes, it would be nice to display such exceptions in a tkinter message box when not starting from a terminal.) In IDLE's deprecated but not intentionally disabled original mode, in which both IDLE and user code are executed in the same process, the working directory would need to be present when executing user code, or its absence would have to be documented. In the former case, delayed imports would have to be more careful. -- Terry Jan Reedy

On 5/13/2022 9:20 PM, ward.davidj@gmail.com wrote:
This is a specific (and now closed) example of import shadowing. The general issue is the subject of https://github.com/python/cpython/issues/67997 -- Terry Jan Reedy

So the "current working directory" is the directory containing the file, right? That would explain the behavior. Probably "Edit with IDLE" should be changed. I have no idea where that is defined. In 3.11 we should be able to make that use the new -P option, which doesn't insert the working directory at the front of sys.path. On Fri, May 13, 2022 at 6:50 PM <ward.davidj@gmail.com> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

On 5/14/2022 12:40 AM, Guido van Rossum wrote:
So the "current working directory" is the directory containing the file, right? That would explain the behavior.
Standard import shadowing.
Probably "Edit with IDLE" should be changed. I have no idea where that is defined.
I presume somewhere in PCBuild. Steve Dower knows and is in charge of the Windows installer.
In 3.11 we should be able to make that use the new -P option, which doesn't insert the working directory at the front of sys.path.
This would only solve the issue for that one of many ways to start IDLE. Example: Entering command 'py -m idlelib', with or without the name of the file added, in a directory with a shadow module. Traceback... ImportError: cannot import name 'InteractiveInterpreter' from 'code' (F:\dev\tem\code.py) The difference is that the import exception is printed: (Yes, it would be nice to display such exceptions in a tkinter message box when not starting from a terminal.) In IDLE's deprecated but not intentionally disabled original mode, in which both IDLE and user code are executed in the same process, the working directory would need to be present when executing user code, or its absence would have to be documented. In the former case, delayed imports would have to be more careful. -- Terry Jan Reedy
participants (4)
-
Guido van Rossum
-
Steve Dower
-
Terry Reedy
-
ward.davidj@gmail.com