]> granicus.if.org Git - python/commitdiff
#1690103: fix initial namespace for code run with trace.main().
authorGeorg Brandl <georg@python.org>
Sun, 1 Aug 2010 08:35:29 +0000 (08:35 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 1 Aug 2010 08:35:29 +0000 (08:35 +0000)
Lib/trace.py
Misc/NEWS

index 077cdc1e341dcc42f13e4b5a0944ff7ba0246595..236ea49dd9d953414d24db2545a8e67ea1c0dfd0 100644 (file)
@@ -799,7 +799,14 @@ def main(argv=None):
         try:
             with open(progname) as fp:
                 code = compile(fp.read(), progname, 'exec')
-            t.run(code)
+            # try to emulate __main__ namespace as much as possible
+            globs = {
+                '__file__': progname,
+                '__name__': '__main__',
+                '__package__': None,
+                '__cached__': None,
+            }
+            t.runctx(code, globs, globs)
         except IOError as err:
             _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
         except SystemExit:
index c342d903e7610693f585b4730622d518d5b632f0..52cbabd0d95d81725fdc35c0de979a86a6da904c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #1690103: Fix initial namespace for code run with trace.main().
+
 - Issue #7395: Fix tracebacks in pstats interactive browser.
 
 - Issue #8230: Fix Lib/test/sortperf.py.