Mailing List Archive

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
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/NKMXPIQPISOPOV6OGASKXV4DEDZUH355/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: 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 [ In reply to ]
On 5/13/2022 9:20 PM, ward.davidj@gmail.com wrote:
>
> https://github.com/python/cpython/issues/92359

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

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/CISOOPMNJGBLFTVV4X5WJHTMFMX6IHEW/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: 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 [ In reply to ]
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:

> 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
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-leave@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/NKMXPIQPISOPOV6OGASKXV4DEDZUH355/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


--
--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-change-the-world/>
Re: 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 [ In reply to ]
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

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/QAMOWEQYZGW73TKTTRREC7LT2DJEZNB7/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: 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 [ In reply to ]
On 5/14/2022 8:37 PM, Terry Reedy wrote:
> On 5/14/2022 12:40 AM, Guido van Rossum wrote:
>> 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.

FTR, the behaviour for the traditional installer lives in
Tools/msi/tcltk/tcltk_reg.wxs, and the behaviour for the Store install
is in PC/python_uwp.cpp.

Cheers,
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/DUTVAITI3PKENGS5HQVQB2JDXQNC6WRB/
Code of Conduct: http://python.org/psf/codeofconduct/