@@ -3067,20 +3067,24 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3067
3067
[orig, res, exc] <evaluate E1>
3068
3068
[orig, res, exc, E1] CHECK_EG_MATCH
3069
3069
[orig, res, rest/exc, match?] COPY 1
3070
- [orig, res, rest/exc, match?, match?] POP_JUMP_IF_NOT_NONE H1
3071
- [orig, res, exc, None] POP_TOP
3072
- [orig, res, exc] JUMP L2
3070
+ [orig, res, rest/exc, match?, match?] POP_JUMP_IF_NONE C1
3073
3071
3074
- [orig, res, rest, match] H1: <assign to V1> (or POP if no V1)
3072
+ [orig, res, rest, match] <assign to V1> (or POP if no V1)
3075
3073
3076
3074
[orig, res, rest] SETUP_FINALLY R1
3077
3075
[orig, res, rest] <code for S1>
3078
3076
[orig, res, rest] JUMP L2
3079
3077
3080
3078
[orig, res, rest, i, v] R1: LIST_APPEND 3 ) exc raised in except* body - add to res
3081
3079
[orig, res, rest, i] POP
3080
+ [orig, res, rest] JUMP LE2
3082
3081
3083
- [orig, res, rest] L2: <evaluate E2>
3082
+ [orig, res, rest] L2: NOP ) for lineno
3083
+ [orig, res, rest] JUMP LE2
3084
+
3085
+ [orig, res, rest/exc, None] C1: POP
3086
+
3087
+ [orig, res, rest] LE2: <evaluate E2>
3084
3088
.............................etc.......................
3085
3089
3086
3090
[orig, res, rest] Ln+1: LIST_APPEND 1 ) add unhandled exc to res (could be None)
@@ -3136,7 +3140,8 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
3136
3140
location loc = LOC (handler );
3137
3141
NEW_JUMP_TARGET_LABEL (c , next_except );
3138
3142
except = next_except ;
3139
- NEW_JUMP_TARGET_LABEL (c , handle_match );
3143
+ NEW_JUMP_TARGET_LABEL (c , except_with_error );
3144
+ NEW_JUMP_TARGET_LABEL (c , no_match );
3140
3145
if (i == 0 ) {
3141
3146
/* create empty list for exceptions raised/reraise in the except* blocks */
3142
3147
/*
@@ -3154,13 +3159,9 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
3154
3159
VISIT (c , expr , handler -> v .ExceptHandler .type );
3155
3160
ADDOP (c , loc , CHECK_EG_MATCH );
3156
3161
ADDOP_I (c , loc , COPY , 1 );
3157
- ADDOP_JUMP (c , loc , POP_JUMP_IF_NOT_NONE , handle_match );
3158
- ADDOP (c , loc , POP_TOP ); // match
3159
- ADDOP_JUMP (c , loc , JUMP , except );
3162
+ ADDOP_JUMP (c , loc , POP_JUMP_IF_NONE , no_match );
3160
3163
}
3161
3164
3162
- USE_LABEL (c , handle_match );
3163
-
3164
3165
NEW_JUMP_TARGET_LABEL (c , cleanup_end );
3165
3166
NEW_JUMP_TARGET_LABEL (c , cleanup_body );
3166
3167
@@ -3219,9 +3220,16 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
3219
3220
/* add exception raised to the res list */
3220
3221
ADDOP_I (c , NO_LOCATION , LIST_APPEND , 3 ); // exc
3221
3222
ADDOP (c , NO_LOCATION , POP_TOP ); // lasti
3222
- ADDOP_JUMP (c , NO_LOCATION , JUMP , except );
3223
+ ADDOP_JUMP (c , NO_LOCATION , JUMP , except_with_error );
3223
3224
3224
3225
USE_LABEL (c , except );
3226
+ ADDOP (c , NO_LOCATION , NOP ); // to hold a propagated location info
3227
+ ADDOP_JUMP (c , NO_LOCATION , JUMP , except_with_error );
3228
+
3229
+ USE_LABEL (c , no_match );
3230
+ ADDOP (c , loc , POP_TOP ); // match (None)
3231
+
3232
+ USE_LABEL (c , except_with_error );
3225
3233
3226
3234
if (i == n - 1 ) {
3227
3235
/* Add exc to the list (if not None it's the unhandled part of the EG) */
0 commit comments