Support for if conditions in list comprehensions
onyb opened this issue · comments
Currently VOC supports list
(and also set
, dict
, generator
) comprehensions, but ignores any if
conditions present.
Excepted result:
>>> [i for i in range(10) if i % 2 == 0]
[0, 2, 4, 6, 8]
Current result in VOC:
>>> [i for i in range(10) if i % 2 == 0]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
I am interested in working on a fix, but would need some pointers.
Thanks for reporting @onyb, indeed list comprehensions are missing some features !
Support for list comprehensions is implemented in the visit_ListComp
method of the ast visitor class.
From a quick glance, I believe these lines have to be evaluated only if the condition is truthy.