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 |
|
|
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 += |
|
|
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 |
|
|
480 |
args = reprlib.repr(frame |
|
|
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 |
|
|
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): |
@@ -277,14 +277,14 b' def test_xmode_skip():' | |||
|
277 | 277 | |
|
278 | 278 | block = dedent( |
|
279 | 279 | """ |
|
280 | def f(): | |
|
281 | __tracebackhide__ = True | |
|
282 | g() | |
|
280 | def f(): | |
|
281 | __tracebackhide__ = True | |
|
282 | g() | |
|
283 | 283 | |
|
284 | def g(): | |
|
285 | raise ValueError | |
|
284 | def g(): | |
|
285 | raise ValueError | |
|
286 | 286 | |
|
287 | f() | |
|
287 | f() | |
|
288 | 288 | """ |
|
289 | 289 | ) |
|
290 | 290 | |
@@ -295,15 +295,15 b' f()' | |||
|
295 | 295 | |
|
296 | 296 | block = dedent( |
|
297 | 297 | """ |
|
298 | def f(): | |
|
299 | __tracebackhide__ = True | |
|
300 | g() | |
|
298 | def f(): | |
|
299 | __tracebackhide__ = True | |
|
300 | g() | |
|
301 | 301 | |
|
302 | def g(): | |
|
303 | from IPython.core.debugger import set_trace | |
|
304 | set_trace() | |
|
302 | def g(): | |
|
303 | from IPython.core.debugger import set_trace | |
|
304 | set_trace() | |
|
305 | 305 | |
|
306 | f() | |
|
306 | f() | |
|
307 | 307 | """ |
|
308 | 308 | ) |
|
309 | 309 | |
@@ -321,3 +321,70 b' f()' | |||
|
321 | 321 | child.expect("ipdb>") |
|
322 | 322 | |
|
323 | 323 | child.close() |
|
324 | ||
|
325 | ||
|
326 | @skip_win32 | |
|
327 | def test_where_erase_value(): | |
|
328 | """Test that `where` does not access f_locals and erase values.""" | |
|
329 | import pexpect | |
|
330 | ||
|
331 | env = os.environ.copy() | |
|
332 | env["IPY_TEST_SIMPLE_PROMPT"] = "1" | |
|
333 | ||
|
334 | child = pexpect.spawn( | |
|
335 | sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env | |
|
336 | ) | |
|
337 | child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE | |
|
338 | ||
|
339 | child.expect("IPython") | |
|
340 | child.expect("\n") | |
|
341 | child.expect_exact("In [1]") | |
|
342 | ||
|
343 | block = dedent( | |
|
344 | """ | |
|
345 | def simple_f(): | |
|
346 | myvar = 1 | |
|
347 | print(myvar) | |
|
348 | 1/0 | |
|
349 | print(myvar) | |
|
350 | simple_f() """ | |
|
351 | ) | |
|
352 | ||
|
353 | for line in block.splitlines(): | |
|
354 | child.sendline(line) | |
|
355 | child.expect_exact(line) | |
|
356 | child.expect_exact("ZeroDivisionError") | |
|
357 | child.expect_exact("In [2]:") | |
|
358 | ||
|
359 | child.sendline("%debug") | |
|
360 | ||
|
361 | ## | |
|
362 | child.expect("ipdb>") | |
|
363 | ||
|
364 | child.sendline("myvar") | |
|
365 | child.expect("1") | |
|
366 | ||
|
367 | ## | |
|
368 | child.expect("ipdb>") | |
|
369 | ||
|
370 | child.sendline("myvar = 2") | |
|
371 | ||
|
372 | ## | |
|
373 | child.expect_exact("ipdb>") | |
|
374 | ||
|
375 | child.sendline("myvar") | |
|
376 | ||
|
377 | child.expect_exact("2") | |
|
378 | ||
|
379 | ## | |
|
380 | child.expect("ipdb>") | |
|
381 | child.sendline("where") | |
|
382 | ||
|
383 | ## | |
|
384 | child.expect("ipdb>") | |
|
385 | child.sendline("myvar") | |
|
386 | ||
|
387 | child.expect_exact("2") | |
|
388 | child.expect("ipdb>") | |
|
389 | ||
|
390 | child.close() |
General Comments 0
You need to be logged in to leave comments.
Login now