Issue #8515: Set __file__ when run file in IDLE.
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Thu, 5 Apr 2012 18:54:39 +0000 (21:54 +0300)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Thu, 5 Apr 2012 18:54:39 +0000 (21:54 +0300)
Lib/idlelib/NEWS.txt
Lib/idlelib/ScriptBinding.py
Misc/ACKS
Misc/NEWS

index d50abd44d29b69782ccc2c83f8a5728e4b57b6eb..b28e58ad3323839f792fbc5f8b0d5ae3c88f0853 100644 (file)
@@ -1,6 +1,9 @@
 What's New in IDLE 3.3?
 =========================
 
+- Issue #8515: Set __file__ when run file in IDLE.
+  Initial patch by Bruce Frederiksen.
+
 - IDLE can be launched as `python -m idlelib`
 
 - Issue #14409: IDLE now properly executes commands in the Shell window
index 18ce9650aed30ba9cb5bdcaa480641736f56d79d..528adf67a611f4c0590d696f0261cac18a92be00 100644 (file)
@@ -150,16 +150,16 @@ class ScriptBinding:
         dirname = os.path.dirname(filename)
         # XXX Too often this discards arguments the user just set...
         interp.runcommand("""if 1:
-            _filename = %r
+            __file__ = {filename!r}
             import sys as _sys
             from os.path import basename as _basename
             if (not _sys.argv or
-                _basename(_sys.argv[0]) != _basename(_filename)):
-                _sys.argv = [_filename]
+                _basename(_sys.argv[0]) != _basename(__file__)):
+                _sys.argv = [__file__]
             import os as _os
-            _os.chdir(%r)
-            del _filename, _sys, _basename, _os
-            \n""" % (filename, dirname))
+            _os.chdir({dirname!r})
+            del _sys, _basename, _os
+            \n""".format(filename=filename, dirname=dirname))
         interp.prepend_syspath(filename)
         # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
         #         go to __stderr__.  With subprocess, they go to the shell.
index 873e8229291cd4e79955362f7203562a830ba70e..dad7ebdef4f1ac184af9cf0ef60595ad58f832e3 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -333,6 +333,7 @@ Doug Fort
 John Fouhy
 Andrew Francis
 Martin Franklin
+Bruce Frederiksen
 Robin Friedrich
 Ivan Frohne
 Matthias Fuchs
index e2e0a2d5fc5c9b6cad0e2061188905ed52391968..b4a00912761860bf60df72a3347141a31b5f95ce 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8515: Set __file__ when run file in IDLE.
+  Initial patch by Bruce Frederiksen.
+
 - Issue #14496: Fix wrong name in idlelib/tabbedpages.py.
   Patch by Popa Claudiu.