diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-03-05 19:23:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-05 19:23:08 (GMT) |
commit | 6935a511670797a3aaebdf96aad3dcff66baa76e (patch) | |
tree | f60c0fbcefbf6cde9672709161ae3962b9930c3a /Lib/idlelib/pyshell.py | |
parent | 73a43960c7be50e136c5482404980175cb99f611 (diff) | |
download | cpython-6935a511670797a3aaebdf96aad3dcff66baa76e.zip cpython-6935a511670797a3aaebdf96aad3dcff66baa76e.tar.gz cpython-6935a511670797a3aaebdf96aad3dcff66baa76e.tar.bz2 |
bpo-32984: IDLE - set __file__ for startup files (GH-5981)
Like Python, IDLE optionally runs one startup file in the Shell window
before presenting the first interactive input prompt. For IDLE,
option -s runs a file named in environmental variable IDLESTARTUP or
PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup
file name before running the file and unsets it before the first
prompt. IDLE now does the same when run normally, without the -n
option.
(cherry picked from commit 22c82be5df70c3d51e3f89b54fe1d4fb84728c1e)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/pyshell.py')
-rwxr-xr-x | Lib/idlelib/pyshell.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index 8b07d52..ee13131 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -635,6 +635,9 @@ class ModifiedInterpreter(InteractiveInterpreter): if source is None: with tokenize.open(filename) as fp: source = fp.read() + if use_subprocess: + source = (f"__file__ = r'''{os.path.abspath(filename)}'''\n" + + source + "\ndel __file__") try: code = compile(source, filename, "exec") except (OverflowError, SyntaxError): |