| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -609,6 +609,58 @@ def run(tracer): | |||
| 609 | 609 | self.compare_events(doit_async.__code__.co_firstlineno, | |
| 610 | 610 | tracer.events, events) | |
| 611 | 611 | ||
| 612 | + def test_async_for_backwards_jump_has_no_line(self): | ||
| 613 | + async def arange(n): | ||
| 614 | + for i in range(n): | ||
| 615 | + yield i | ||
| 616 | + async def f(): | ||
| 617 | + async for i in arange(3): | ||
| 618 | + if i > 100: | ||
| 619 | + break # should never be traced | ||
| 620 | + | ||
| 621 | + tracer = self.make_tracer() | ||
| 622 | + coro = f() | ||
| 623 | + try: | ||
| 624 | + sys.settrace(tracer.trace) | ||
| 625 | + coro.send(None) | ||
| 626 | + except Exception: | ||
| 627 | + pass | ||
| 628 | + finally: | ||
| 629 | + sys.settrace(None) | ||
| 630 | + | ||
| 631 | + events = [ | ||
| 632 | + (0, 'call'), | ||
| 633 | + (1, 'line'), | ||
| 634 | + (-3, 'call'), | ||
| 635 | + (-2, 'line'), | ||
| 636 | + (-1, 'line'), | ||
| 637 | + (-1, 'return'), | ||
| 638 | + (1, 'exception'), | ||
| 639 | + (2, 'line'), | ||
| 640 | + (1, 'line'), | ||
| 641 | + (-1, 'call'), | ||
| 642 | + (-2, 'line'), | ||
| 643 | + (-1, 'line'), | ||
| 644 | + (-1, 'return'), | ||
| 645 | + (1, 'exception'), | ||
| 646 | + (2, 'line'), | ||
| 647 | + (1, 'line'), | ||
| 648 | + (-1, 'call'), | ||
| 649 | + (-2, 'line'), | ||
| 650 | + (-1, 'line'), | ||
| 651 | + (-1, 'return'), | ||
| 652 | + (1, 'exception'), | ||
| 653 | + (2, 'line'), | ||
| 654 | + (1, 'line'), | ||
| 655 | + (-1, 'call'), | ||
| 656 | + (-2, 'line'), | ||
| 657 | + (-2, 'return'), | ||
| 658 | + (1, 'exception'), | ||
| 659 | + (1, 'return'), | ||
| 660 | + ] | ||
| 661 | + self.compare_events(f.__code__.co_firstlineno, | ||
| 662 | + tracer.events, events) | ||
| 663 | + | ||
| 612 | 664 | def test_21_repeated_pass(self): | |
| 613 | 665 | def func(): | |
| 614 | 666 | pass | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Backward jumps after ``async for`` loops are no longer given dubious line numbers. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3148,6 +3148,8 @@ compiler_async_for(struct compiler *c, stmt_ty s) | |||
| 3148 | 3148 | /* Success block for __anext__ */ | |
| 3149 | 3149 | VISIT(c, expr, s->v.AsyncFor.target); | |
| 3150 | 3150 | VISIT_SEQ(c, stmt, s->v.AsyncFor.body); | |
| 3151 | + /* Mark jump as artificial */ | ||
| 3152 | + UNSET_LOC(c); | ||
| 3151 | 3153 | ADDOP_JUMP(c, JUMP, start); | |
| 3152 | 3154 | ||
| 3153 | 3155 | compiler_pop_fblock(c, FOR_LOOP, start); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments