[Python-checkins] r54363 - in python/trunk: Lib/pdb.py Misc/NEWS

georg.brandl python-checkins at python.org
Tue Mar 13 22:58:47 CET 2007


Author: georg.brandl
Date: Tue Mar 13 22:58:44 2007
New Revision: 54363

Modified:
   python/trunk/Lib/pdb.py
   python/trunk/Misc/NEWS
Log:
Patch #1429539: pdb now correctly initializes the __main__ module for
the debugged script, which means that imports from __main__ work
correctly now.


Modified: python/trunk/Lib/pdb.py
==============================================================================
--- python/trunk/Lib/pdb.py	(original)
+++ python/trunk/Lib/pdb.py	Tue Mar 13 22:58:44 2007
@@ -1147,12 +1147,18 @@
         return None
 
     def _runscript(self, filename):
-        # Start with fresh empty copy of globals and locals and tell the script
-        # that it's being run as __main__ to avoid scripts being able to access
-        # the pdb.py namespace.
-        globals_ = {"__name__" : "__main__"}
-        locals_ = globals_
-
+        # The script has to run in __main__ namespace (or imports from
+        # __main__ will break).
+        # 
+        # So we clear up the __main__ and set several special variables
+        # (this gets rid of pdb's globals and cleans old variables on restarts).
+        import __main__
+        __main__.__dict__.clear()
+        __main__.__dict__.update({"__name__"    : "__main__",
+                                  "__file__"    : filename,
+                                  "__builtins__": __builtins__,
+                                 })
+        
         # When bdb sets tracing, a number of call and line events happens
         # BEFORE debugger even reaches user's code (and the exact sequence of
         # events depends on python version). So we take special measures to
@@ -1162,7 +1168,7 @@
         self.mainpyfile = self.canonic(filename)
         self._user_requested_quit = 0
         statement = 'execfile( "%s")' % filename
-        self.run(statement, globals=globals_, locals=locals_)
+        self.run(statement) 
 
 # Simplified interface
 
@@ -1259,5 +1265,6 @@
 
 
 # When invoked as main program, invoke the debugger on a script
-if __name__=='__main__':
-    main()
+if __name__ == '__main__':
+    import pdb
+    pdb.main()

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Mar 13 22:58:44 2007
@@ -170,6 +170,10 @@
 Library
 -------
 
+- Patch #1429539: pdb now correctly initializes the __main__ module for
+  the debugged script, which means that imports from __main__ work
+  correctly now.
+
 - The nonobvious commands.getstatus() function is now deprecated.
 
 - Patch #1393667: pdb now has a "run" command which restarts the debugged


More information about the Python-checkins mailing list