From 203139eafa36d0ed805a2c32c00b91a3a804e18f Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 31 Dec 2021 11:27:15 -0500 Subject: [PATCH] Add tests, comment what's up with change.. and use isinstance() --- .../02_loop_continue_dead_code.pyc | Bin 0 -> 448 bytes .../02_loop_continue_dead_code.pyc | Bin 0 -> 489 bytes .../02_loop_continue_dead_code.pyc | Bin 0 -> 483 bytes .../bug24/02_loop_continue_dead_code.py | 18 ++++++++++++++++++ uncompyle6/semantics/transform.py | 3 ++- 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/bytecode_2.4_run/02_loop_continue_dead_code.pyc create mode 100644 test/bytecode_2.6_run/02_loop_continue_dead_code.pyc create mode 100644 test/bytecode_2.7_run/02_loop_continue_dead_code.pyc create mode 100644 test/simple_source/bug24/02_loop_continue_dead_code.py diff --git a/test/bytecode_2.4_run/02_loop_continue_dead_code.pyc b/test/bytecode_2.4_run/02_loop_continue_dead_code.pyc new file mode 100644 index 0000000000000000000000000000000000000000..94a416f8d183fee4052168c4e65061e9b0856ff4 GIT binary patch literal 448 zcmZ{g%}N6?5XWb-+b&uKZ{DQhWiPc_^d>0ixrePF2olyLZWnhqYm-7N^;F-_ckv0F zNh_WV%rF0BJ~ET~dw+L1_{tS*S48^_nL8n9fJY+2CkX_Dpd-)%3IS^bq{AeQIrxZh zKP_Fqo!MfR*L{-CR4)THHR`o&ierToBDQwRIah?mC9DAMo(AxNutKmg;9C;R3$Q&v zAHf$Wn| z+4)SF;q$y0T@24gva+_7$~L}i=0<9hYdUFj+AjSeW&Pvsa=`-vU;8c2%4Z;PyvzvD+2Lh7PWoz zA>($Q+J3n($s*4CoLZed4dh(Q=d?(UBymf?;RjrC*fHbv0!!ffVSsnSl3?1Pm#_&3 zm>$RxR#;y;p1Mx&*w`%ciqpvJaT9AbtQ)>Xew6DlY-XHw-enQzI^rD-?3pj7d6{Wp zO|_7E_*f;Q^Wo`8WX6<2n!=?;rG?V5;*-)RW$h05)gR@q7u;unLUbvlcF+n!>ILbB o(~!$TC?kcq@%9>LQ&Vg>`;WaXmK^6sRhho@Q?37ax3j(b16c88EC2ui literal 0 HcmV?d00001 diff --git a/test/bytecode_2.7_run/02_loop_continue_dead_code.pyc b/test/bytecode_2.7_run/02_loop_continue_dead_code.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9e814d8c07a944af6e6925c709b6e9131850fb8c GIT binary patch literal 483 zcmbu4u};G<5QhItXbKf&WkW?Q=}<~51_p$XVD3PXkdTlSY?DSLafls>qB52D<6(FK z&Viu|6PEAuo$q}2JN)YRmZQ%^;&+97Ub5LEh63)Hgb#KInxI0c0BL|VfjF4QTfX>! zal6RupsGz;C&hqWtMjLkTxj{6mFb}*E(w0^%D*{dyiTwJt{;YYC#(o{7ccF0Ks|&b ztO4RH#}j|NI~FyMeYaU0GP#EPv|P4)i~ShaVc6U_>%77;DRj&yTG)wCW<`~2VNFv@ zJ$`J`>FM}nDsp2gAx-JBve826L~*3_akX^&{OXT%~c~F kWuy={URg?=(1M!ArZvX%Q literal 0 HcmV?d00001 diff --git a/test/simple_source/bug24/02_loop_continue_dead_code.py b/test/simple_source/bug24/02_loop_continue_dead_code.py new file mode 100644 index 00000000..cbe5008e --- /dev/null +++ b/test/simple_source/bug24/02_loop_continue_dead_code.py @@ -0,0 +1,18 @@ +"""This program is self-checking!""" +# Python 2.4 - 2.7 bug in transforming "else if" to "elif" in Python 2.4 .. 2.7 +# From Issue #377 + +# RUNNABLE! +def loop_continue_dead_code(slots): + for name in slots: + if name: + pass + else: + continue + # The below is dead code + if x: + y() + else: + z() + +loop_continue_dead_code([None, 1]) diff --git a/uncompyle6/semantics/transform.py b/uncompyle6/semantics/transform.py index d21104bc..30751c16 100644 --- a/uncompyle6/semantics/transform.py +++ b/uncompyle6/semantics/transform.py @@ -293,7 +293,8 @@ class TreeTransform(GenericASTTraversal, object): else_suite_index = 1 len_n = len(n) - if len_n == 1 and type(n[0]) is SyntaxTree and len(n[0]) == 1 and n[0] == "stmt": + # Sometimes stmt is reduced away and n[0] can be a single reduction like continue -> CONTINUE. + if len_n == 1 and isinstance(n[0], SyntaxTree) and len(n[0]) == 1 and n[0] == "stmt": n = n[0][0] elif len_n == 0: return node