@@ -493,51 +493,6 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
493
493
return tokens [last - 3 ].kind not in frozenset (
494
494
("JUMP_FORWARD" , "RETURN_VALUE" )
495
495
) or (tokens [last - 3 ] == "JUMP_FORWARD" and tokens [last - 3 ].attr != 2 )
496
- elif lhs == "tryelsestmt" :
497
- # We need to distinguish "try_except" from "tryelsestmt"; we do that
498
- # by making sure that the jump before the except handler jumps to
499
- # code somewhere before the end of the construct.
500
- # This AST method is slower, but the token-only based approach
501
- # didn't work as it failed with a "try" embedded inside a "try/else"
502
- # since we can't detect COME_FROM boundaries.
503
-
504
- if ast [3 ] == "except_handler" :
505
- except_handler = ast [3 ]
506
- if except_handler [0 ] == "JUMP_FORWARD" :
507
- else_start = int (except_handler [0 ].pattr )
508
- if last == len (tokens ):
509
- last -= 1
510
- if tokens [last ] == "COME_FROM" and isinstance :
511
- last_offset = int (tokens [last ].offset .split ("_" )[0 ])
512
- return else_start >= last_offset
513
-
514
- # The above test apparently isn't good enough, so we have additional
515
- # checks distinguish "try_except" from "tryelsestmt". we do that
516
- # by checking the jump before the "END_FINALLY".
517
- # If we have:
518
- # insn
519
- # POP_TOP
520
- # END_FINALLY
521
- # COME_FROM
522
- # then insn is neither a JUMP_FORWARD nor RETURN_VALUE,
523
- # or if it is JUMP_FORWARD, then it can't be a JUMP_FORWARD to right after
524
- # COME_FROM
525
- if last == len (tokens ):
526
- last -= 1
527
- while tokens [last - 1 ] == "COME_FROM" and tokens [last - 2 ] == "COME_FROM" :
528
- last -= 1
529
- if tokens [last ] == "COME_FROM" and tokens [last - 1 ] == "COME_FROM" :
530
- last -= 1
531
- if (
532
- tokens [last ] == "COME_FROM"
533
- and tokens [last - 1 ] == "END_FINALLY"
534
- and tokens [last - 2 ] == "POP_TOP"
535
- ):
536
- # A jump of 2 is a jump around POP_TOP, END_FINALLY which
537
- # would indicate try/else rather than try
538
- return tokens [last - 3 ].kind in frozenset (
539
- ("JUMP_FORWARD" , "RETURN_VALUE" )
540
- ) and (tokens [last - 3 ] != "JUMP_FORWARD" or tokens [last - 3 ].attr == 2 )
541
496
542
497
return False
543
498
0 commit comments