@@ -206,7 +206,7 @@ def mouse_input_wrapper(prompt=''):
206206 BANNED_BUILTINS .append ('input' )
207207
208208
209- IGNORE_VARS = set (('__user_stdout__' , '__builtins__' , '__name__' , '__exception__' , '__doc__' , '__package__' ))
209+ IGNORE_VARS = set (('__user_stdout__' , '__OPT_toplevel__' , ' __builtins__' , '__name__' , '__exception__' , '__doc__' , '__package__' ))
210210
211211def get_user_stdout (frame ):
212212 return frame .f_globals ['__user_stdout__' ].getvalue ()
@@ -557,6 +557,12 @@ def interaction(self, frame, traceback, event_type):
557557 if top_frame .f_code .co_name == '__repr__' :
558558 return
559559
560+ # if top_frame.f_globals doesn't contain the sentinel '__OPT_toplevel__',
561+ # then we're in another global scope altogether, so skip it!
562+ # (this comes up in tests/backend-tests/namedtuple.txt)
563+ if '__OPT_toplevel__' not in top_frame .f_globals :
564+ return
565+
560566
561567 # OLD CODE -- bail if any element on the stack matches these conditions
562568 # note that the old code passes tests/backend-tests/namedtuple.txt
@@ -1047,7 +1053,9 @@ def _runscript(self, script_str, custom_globals=None):
10471053
10481054 user_globals = {"__name__" : "__main__" ,
10491055 "__builtins__" : user_builtins ,
1050- "__user_stdout__" : user_stdout }
1056+ "__user_stdout__" : user_stdout ,
1057+ # sentinel value for frames deriving from a top-level module
1058+ "__OPT_toplevel__" : True }
10511059
10521060 if custom_globals :
10531061 user_globals .update (custom_globals )
0 commit comments