[Python-checkins] cpython: Issue #8515: Set __file__ when run file in IDLE.

andrew.svetlov python-checkins at python.org
Thu Apr 5 20:55:20 CEST 2012


http://hg.python.org/cpython/rev/2c276d0553ff
changeset:   76126:2c276d0553ff
user:        Andrew Svetlov <andrew.svetlov at gmail.com>
date:        Thu Apr 05 21:54:39 2012 +0300
summary:
  Issue #8515: Set __file__ when run file in IDLE.

files:
  Lib/idlelib/NEWS.txt         |   3 +++
  Lib/idlelib/ScriptBinding.py |  12 ++++++------
  Misc/ACKS                    |   1 +
  Misc/NEWS                    |   3 +++
  4 files changed, 13 insertions(+), 6 deletions(-)


diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -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
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/ScriptBinding.py
@@ -150,16 +150,16 @@
         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.
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -333,6 +333,7 @@
 John Fouhy
 Andrew Francis
 Martin Franklin
+Bruce Frederiksen
 Robin Friedrich
 Ivan Frohne
 Matthias Fuchs
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list