DebugClientBase: fixed an issue related to the Python scoping rules. Needed to emulate it in the debugger backend.

Sat, 13 Mar 2021 19:45:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 13 Mar 2021 19:45:36 +0100
changeset 8159
08b8b3d2deb1
parent 8158
16a34a0167ba
child 8160
d1057f83610e

DebugClientBase: fixed an issue related to the Python scoping rules. Needed to emulate it in the debugger backend.

eric6/DebugClients/Python/DebugClientBase.py file | annotate | diff | comparison | revisions
--- a/eric6/DebugClients/Python/DebugClientBase.py	Sat Mar 13 15:55:35 2021 +0100
+++ b/eric6/DebugClients/Python/DebugClientBase.py	Sat Mar 13 19:45:36 2021 +0100
@@ -626,20 +626,27 @@
                                     _locals = (
                                         self.currentThread.getFrameLocals(
                                             self.framenr))
+                            # transfer all locals into a new globals
+                            # to emulate Python scoping rules
+                            _updatedGlobals = {}
+                            _updatedGlobals.update(_globals)
+                            _updatedGlobals.update(_locals)
                             #- reset sys.stdout to our redirector
                             #- (unconditionally)
                             if "sys" in _globals:
-                                __stdout = _globals["sys"].stdout
-                                _globals["sys"].stdout = self.writestream
-                                exec(code, _globals, _locals)       # secok
-                                _globals["sys"].stdout = __stdout
+                                __stdout = _updatedGlobals["sys"].stdout
+                                _updatedGlobals["sys"].stdout = (
+                                    self.writestream
+                                )
+                                exec(code, _updatedGlobals, _locals)    # secok
+                                _updatedGlobals["sys"].stdout = __stdout
                             elif "sys" in _locals:
                                 __stdout = _locals["sys"].stdout
                                 _locals["sys"].stdout = self.writestream
-                                exec(code, _globals, _locals)       # secok
+                                exec(code, _updatedGlobals, _locals)    # secok
                                 _locals["sys"].stdout = __stdout
                             else:
-                                exec(code, _globals, _locals)       # secok
+                                exec(code, _updatedGlobals, _locals)    # secok
                             
                             self.currentThread.storeFrameLocals(self.framenr)
                     except SystemExit as exc:

eric ide

mercurial