From b57ca392a202df3f37843f34b3ba870df717089d Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 8 May 2019 16:27:41 -0400 Subject: [PATCH] 2.7 confusion around "and" vs comprehension "if" Fixes #225 --- test/bytecode_2.6_run/01_ifelse_listcomp.pyc | Bin 371 -> 740 bytes test/bytecode_2.7_run/01_ifelse_listcomp.pyc | Bin 329 -> 685 bytes test/simple_source/bug26/01_ifelse_listcomp.py | 7 +++++++ uncompyle6/parsers/parse27.py | 6 ++++++ 4 files changed, 13 insertions(+) diff --git a/test/bytecode_2.6_run/01_ifelse_listcomp.pyc b/test/bytecode_2.6_run/01_ifelse_listcomp.pyc index efe324ab2ef5401bf8d615a5b24c8a38790ff181..7bba8d75efd83b19d60326feb8cf00a0fa24105d 100644 GIT binary patch delta 386 zcmXX>-AV#c5dLPj{S&ejx=IQPVsDDBBv7IY?*apbge5P+vw1c!f6f8DFofy_#HZ+O z3SXfos26Bv^}x(GKi|xJ=g;}^D&N1mg~QtVp@;1&Fy6445-lsA3*|t$P&-f_`W})1 z8c0ISPM~~z0BL~6JE76tM-oACAw(LXKK??7L(Rj0B2)#O4S1+NI~WBZ>*0++DnL69 z`D*5|vkp6*2`r$~Jk7LqxjNOuO?TKMPK79CQE$%K&CW0fy2p4W%n2Fa1X$iM0&#v% zV;^E2R@9DV+{zx^j0LQG-q^>9HPg&$?(c2YTwLb7r`0K4RZPURdOv+hXQRorBt|wx kXvT%*`nH@?2f5CHY00-%M|4*%a?qlddq6&w;8T(Q0Sr_=EdT%j delta 66 zcmaFD`k6`Q;wN6Nk3vtQk{O_Y9Y{L>aq$X|A;ithqS&hkiax;@Z J8%QvS5da>y4R8Pe diff --git a/test/bytecode_2.7_run/01_ifelse_listcomp.pyc b/test/bytecode_2.7_run/01_ifelse_listcomp.pyc index b110fca990212b15c61641e59735ba49f5dc126f..359f5046eb90c5a92b163a1199cb3ef2924cd04f 100644 GIT binary patch delta 370 zcmXYs!AiqG5QhIrvPmr}MG(Pw5)V0vr=nPjhtgvO1%+S_(v3}&TAN*H50!%Y0`Wb( z3qFBoAEknLb0%?N=iB*rX6N5e=S_v~a;+X7e_ajmzZCO?xA`f;*M)YVU1$$lVW!ABCHHF?J+A2V(SG@&VQDkwDX9GE4nhbMv#a30lo zWG1t%!y(NoERvF0YF$>R>9~@|1L9N)MHcI3kHZ}3Z{v|LC*1NlfSu*8q!%<{C&YuK z%SwCNiv+gL!Px8EnrUX!>RyWW4=j1io8tFy$E@(FHB9c4*+brz#7K>gUQ{bSjyB2{ aN2R-wIg`&6-=~dLW|z9|Ci%2Q>+}Z*(>`7R delta 65 zcmZ3>dXh<+`7-t$qZ1y3Zxx?xOl=u=}COS8caZTCP>gvgLN`9ljUSTCVw`N Hpc^9q!nzBW diff --git a/test/simple_source/bug26/01_ifelse_listcomp.py b/test/simple_source/bug26/01_ifelse_listcomp.py index efedeb63..3973c451 100644 --- a/test/simple_source/bug26/01_ifelse_listcomp.py +++ b/test/simple_source/bug26/01_ifelse_listcomp.py @@ -2,3 +2,10 @@ # This is RUNNABLE! assert [False, True, True, True, True] == [False if not a else True for a in range(5)] assert [True, False, False, False, False] == [False if a else True for a in range(5)] + +# From bug #225 +m = ['hi', 'he', 'ih', 'who', 'ho'] +ms = {} +for f in (f for f in m if f.startswith('h')): + ms[f] = 5 +assert ms == {'hi': 5, 'he': 5, 'ho': 5} diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index e9c176d3..b3228e35 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -229,6 +229,12 @@ class Python27Parser(Python2Parser): return invalid if rule == ('and', ('expr', 'jmp_false', 'expr', '\\e_come_from_opt')): + # If the instruction after the instructions formin "and" is an "YIELD_VALUE" + # then this is probably an "if" inside a comprehension. + if tokens[last] == 'YIELD_VALUE': + # Note: We might also consider testing last+1 being "POP_TOP" + return True + # Test that jmp_false jumps to the end of "and" # or that it jumps to the same place as the end of "and" jmp_false = ast[1][0]