classification
Title: IDLE: Don't run internal code in user namespace.
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: ZackerySpytz, terry.reedy
Priority: normal Keywords: patch

Created on 2019-09-10 01:37 by terry.reedy, last changed 2021-02-01 22:30 by terry.reedy. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20040 closed ZackerySpytz, 2020-05-11 22:36
Messages (2)
msg351562 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-09-10 01:37
#38077 fixed the bug of internal runcommand code not deleting 'argv' from the user namespace.  This issue is about not running code there.

When a subprocess is running, pyshell.ModifiedInterpreter.runcommand runs python code created by IDLE in locals == __main__.__dict__, the same as code enter by a user.  This requires that the code carefully clean up after itself.  I believe the same effect could by had more safely by exec-ing internal commands in the run module dict or a fresh temporary dict.

Possible solution.  In run.Executive.runcode, add 'user=True' to runcode signature, add 'if user else {}' to 'self.locals' arg, and add
    def runcommand(self, code):
        return self.runcode(code, user=False).  Then replace 'runcode' with 'runcommand' in pyshell runcommand body.
msg386119 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-02-01 22:30
Zachery, thank you for the PR to test.  It turns out that the proposed change is more dangerous the the possible error it prevent.  I could have easily missed the problem (not setting __file__, see PR).

Before considering this again, I need to list ways to run user code with Python and what envivonment (cwd, path, dir() results.  Then see what IDLE does in corresponding situations.
History
Date User Action Args
2021-02-01 22:30:00terry.reedysetstatus: open -> closed
resolution: rejected
messages: + msg386119

stage: patch review -> resolved
2020-05-11 22:36:36ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request19351
stage: needs patch -> patch review
2019-09-10 01:37:51terry.reedycreate