Message192053
The purpose of the function is to create a command line for the user subprocess. Most of its body:
'''
# Maybe IDLE is installed and is being accessed via sys.path,
# or maybe it's not installed and the idle.py script is being
# run from the IDLE source directory.
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
default=False, type='bool')
if __name__ == 'idlelib.PyShell':
command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,)
else:
command = "__import__('run').main(%r)" % (del_exitf,)
return [sys.executable] + w + ["-c", command, str(self.port)]
'''
Question: is it really important to avoid binding the run module to 'run' in the user process? If so, maybe we should use importlib.import_module, as 'direct use of __import__ is entirely discouraged".
The first command looks 'funny' because of the repetition of 'run'. The reason is that __import__('idlelib.run') returns idlelib, not idlelib.run. Perhaps it would work to delete .run in the import, or to use importlib.import_module.
The second command incorrectly assumes that if __name__ == '__main__' (the alternative to 'idlelib.PyShell'), then the directory containing PyShell and run is the current working directory. This is true if PyShell is run from that directory, but
F:\Python\dev\py33\PCbuild>python_d -m idlelib.PyShell
F:\Python\dev\py33\PCbuild>python_d ../Lib/idlelib/PyShell.py
both report "ImportError: No module named 'run'" and open a shell window and error message box a few seconds later. The shell closes when the messagebox is dismissed.
It seems to me that the 'else' caters to a non-existent or impossible use case. PyShell has several 'from idlelib.X import Y' statements. If those work, then "from idlelib import run' must work, and so too must the function equivalent. |
|
Date |
User |
Action |
Args |
2013-06-29 22:09:24 | terry.reedy | set | recipients:
+ terry.reedy, roger.serwy |
2013-06-29 22:09:24 | terry.reedy | set | messageid: <1372543764.27.0.834894616208.issue18330@psf.upfronthosting.co.za> |
2013-06-29 22:09:24 | terry.reedy | link | issue18330 messages |
2013-06-29 22:09:23 | terry.reedy | create | |
|