Repository: xonsh/xonsh

Issue:
Wrong result of list comprehension with multiple if clauses
It seems that for list comprehensions with multiple `if` clauses only the first condition gets evaluated:

## Expected Behavior
```python
$ [i for i in range(10) if i > 2 if i < 5]
[3, 4]
```

## Current Behavior
```python
$ [i for i in range(10) if i > 2 if i < 5]
[3, 4, 5, 6, 7, 8, 9]
```

## xonfig

<details>

```
+------------------+----------------------+
| xonsh            | 0.9.19               |
| Git SHA          | 1001603f             |
| Commit Date      | Aug 24 16:41:28 2020 |
| Python           | 3.8.3                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.4                |
| shell type       | prompt_toolkit       |
| pygments         | 2.6.1                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | arch                 |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```

</details>

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/parsers/base.py b/xonsh/parsers/base.py
--- a/xonsh/parsers/base.py
+++ b/xonsh/parsers/base.py
@@ -2844,6 +2844,7 @@ def p_comp_if(self, p):
         p0 = {"if": [p2]}
         if p3 is not None:
             p0["comps"] = p3.get("comps", [])
+            p0["if"] += p3.get("if", [])
         p[0] = p0
 
     def p_yield_expr(self, p):
diff --git a/xonsh/parsers/v36.py b/xonsh/parsers/v36.py
--- a/xonsh/parsers/v36.py
+++ b/xonsh/parsers/v36.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 """Implements the xonsh parser for Python v3.6."""
 import xonsh.ast as ast
-from xonsh.parsers.base import store_ctx, ensure_has_elts, lopen_loc, BaseParser
+from xonsh.parsers.base import store_ctx, lopen_loc, BaseParser
 
 
 class Parser(BaseParser):
@@ -149,20 +149,9 @@ def p_argument_eq(self, p):
 
     def p_comp_for(self, p):
         """comp_for : FOR exprlist IN or_test comp_iter_opt"""
-        targs, it, p5 = p[2], p[4], p[5]
-        if len(targs) == 1:
-            targ = targs[0]
-        else:
-            targ = ensure_has_elts(targs)
-        store_ctx(targ)
+        super().p_comp_for(p)
         # only difference with base should be the is_async=0
-        comp = ast.comprehension(target=targ, iter=it, ifs=[], is_async=0)
-        comps = [comp]
-        p0 = {"comps": comps}
-        if p5 is not None:
-            comps += p5.get("comps", [])
-            comp.ifs += p5.get("if", [])
-        p[0] = p0
+        p[0]["comps"][0].is_async = 0
 
     def p_expr_stmt_annassign(self, p):
         """expr_stmt : testlist_star_expr COLON test EQUALS test"""


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -793,6 +793,10 @@ def test_listcomp_if_and():
     check_ast('[x for x in "mom" if True and x == "m"]')
 
 
+def test_listcomp_multi_if():
+    check_ast('[x for x in "mom" if True if x in "mo" if x == "m"]')
+
+
 def test_dbl_listcomp():
     check_ast('[x+y for x in "mom" for y in "dad"]')