##// END OF EJS Templates
Don't access current_frame f_locals...
Matthias Bussonnier -
Show More
@@ -331,7 +331,7 b' class Pdb(OldPdb):'
331 331 if frame in (self.curframe, getattr(self, "initial_frame", None)):
332 332 return False
333 333 else:
334 return frame.f_locals.get("__tracebackhide__", False)
334 return self._get_frame_locals(frame).get("__tracebackhide__", False)
335 335
336 336 return False
337 337
@@ -435,6 +435,28 b' class Pdb(OldPdb):'
435 435 self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
436 436 # vds: <<
437 437
438 def _get_frame_locals(self, frame):
439 """ "
440 Acessing f_local of current frame reset the namespace, so we want to avoid
441 that or the following can happend
442
443 ipdb> foo
444 "old"
445 ipdb> foo = "new"
446 ipdb> foo
447 "new"
448 ipdb> where
449 ipdb> foo
450 "old"
451
452 So if frame is self.current_frame we instead return self.curframe_locals
453
454 """
455 if frame is self.curframe:
456 return self.curframe_locals
457 else:
458 return frame.f_locals
459
438 460 def format_stack_entry(self, frame_lineno, lprefix=': ', context=None):
439 461 if context is None:
440 462 context = self.context
@@ -459,10 +481,11 b' class Pdb(OldPdb):'
459 481 frame, lineno = frame_lineno
460 482
461 483 return_value = ''
462 if '__return__' in frame.f_locals:
463 rv = frame.f_locals['__return__']
464 #return_value += '->'
465 return_value += reprlib.repr(rv) + '\n'
484 loc_frame = self._get_frame_locals(frame)
485 if "__return__" in loc_frame:
486 rv = loc_frame["__return__"]
487 # return_value += '->'
488 return_value += reprlib.repr(rv) + "\n"
466 489 ret.append(return_value)
467 490
468 491 #s = filename + '(' + `lineno` + ')'
@@ -474,10 +497,10 b' class Pdb(OldPdb):'
474 497 else:
475 498 func = "<lambda>"
476 499
477 call = ''
478 if func != '?':
479 if '__args__' in frame.f_locals:
480 args = reprlib.repr(frame.f_locals['__args__'])
500 call = ""
501 if func != "?":
502 if "__args__" in loc_frame:
503 args = reprlib.repr(loc_frame["__args__"])
481 504 else:
482 505 args = '()'
483 506 call = tpl_call % (func, args)
@@ -671,7 +694,7 b' class Pdb(OldPdb):'
671 694
672 695 def getsourcelines(self, obj):
673 696 lines, lineno = inspect.findsource(obj)
674 if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
697 if inspect.isframe(obj) and obj.f_globals is self._get_frame_locals(obj):
675 698 # must be a module frame: do not try to cut a block out of it
676 699 return lines, 1
677 700 elif inspect.ismodule(obj):
General Comments 0
You need to be logged in to leave comments. Login now