Skip to content

Commit f8f4d5e

Browse files
committed
Fix Ctx
1 parent bf62f09 commit f8f4d5e

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

parser/grammar.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ test:
12061206
}
12071207
| or_test IF or_test ELSE test
12081208
{
1209-
$$ = &ast.IfExp{ExprBase: ast.ExprBase{$<pos>$}, Test:$1, Body: $3, Orelse: $5} // FIXME Ctx
1209+
$$ = &ast.IfExp{ExprBase: ast.ExprBase{$<pos>$}, Test:$3, Body: $1, Orelse: $5}
12101210
}
12111211
| lambdef
12121212
{
@@ -1258,7 +1258,7 @@ or_test:
12581258
boolop := $$.(*ast.BoolOp)
12591259
boolop.Values = append(boolop.Values, $3)
12601260
} else {
1261-
$$ = &ast.BoolOp{ExprBase: ast.ExprBase{$<pos>$}, Op: ast.Or, Values: []ast.Expr{$$, $3}} // FIXME Ctx
1261+
$$ = &ast.BoolOp{ExprBase: ast.ExprBase{$<pos>$}, Op: ast.Or, Values: []ast.Expr{$$, $3}}
12621262
}
12631263
$<isExpr>$ = false
12641264
}
@@ -1275,7 +1275,7 @@ and_test:
12751275
boolop := $$.(*ast.BoolOp)
12761276
boolop.Values = append(boolop.Values, $3)
12771277
} else {
1278-
$$ = &ast.BoolOp{ExprBase: ast.ExprBase{$<pos>$}, Op: ast.And, Values: []ast.Expr{$$, $3}} // FIXME Ctx
1278+
$$ = &ast.BoolOp{ExprBase: ast.ExprBase{$<pos>$}, Op: ast.And, Values: []ast.Expr{$$, $3}}
12791279
}
12801280
$<isExpr>$ = false
12811281
}
@@ -1359,7 +1359,7 @@ comp_op:
13591359
star_expr:
13601360
'*' expr
13611361
{
1362-
$$ = &ast.Starred{ExprBase: ast.ExprBase{$<pos>$}, Value: $2} // FIXME Ctx
1362+
$$ = &ast.Starred{ExprBase: ast.ExprBase{$<pos>$}, Value: $2, Ctx: ast.Load}
13631363
}
13641364

13651365
expr:

parser/grammar_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ func TestGrammar(t *testing.T) {
114114
{"a+b-c/d//e%f", "eval", "Expression(body=BinOp(left=BinOp(left=Name(id='a', ctx=Load()), op=Add(), right=Name(id='b', ctx=Load())), op=Sub(), right=BinOp(left=BinOp(left=BinOp(left=Name(id='c', ctx=Load()), op=Div(), right=Name(id='d', ctx=Load())), op=FloorDiv(), right=Name(id='e', ctx=Load())), op=Mod(), right=Name(id='f', ctx=Load()))))"},
115115
{"a+b-c/d//e%f**g", "eval", "Expression(body=BinOp(left=BinOp(left=Name(id='a', ctx=Load()), op=Add(), right=Name(id='b', ctx=Load())), op=Sub(), right=BinOp(left=BinOp(left=BinOp(left=Name(id='c', ctx=Load()), op=Div(), right=Name(id='d', ctx=Load())), op=FloorDiv(), right=Name(id='e', ctx=Load())), op=Mod(), right=BinOp(left=Name(id='f', ctx=Load()), op=Pow(), right=Name(id='g', ctx=Load())))))"},
116116
{"a+b-c/d//e%f**g|h&i^k<<l>>m", "eval", "Expression(body=BinOp(left=BinOp(left=BinOp(left=Name(id='a', ctx=Load()), op=Add(), right=Name(id='b', ctx=Load())), op=Sub(), right=BinOp(left=BinOp(left=BinOp(left=Name(id='c', ctx=Load()), op=Div(), right=Name(id='d', ctx=Load())), op=FloorDiv(), right=Name(id='e', ctx=Load())), op=Mod(), right=BinOp(left=Name(id='f', ctx=Load()), op=Pow(), right=Name(id='g', ctx=Load())))), op=BitOr(), right=BinOp(left=BinOp(left=Name(id='h', ctx=Load()), op=BitAnd(), right=Name(id='i', ctx=Load())), op=BitXor(), right=BinOp(left=BinOp(left=Name(id='k', ctx=Load()), op=LShift(), right=Name(id='l', ctx=Load())), op=RShift(), right=Name(id='m', ctx=Load())))))"},
117+
{"a if b else c", "eval", "Expression(body=IfExp(test=Name(id='b', ctx=Load()), body=Name(id='a', ctx=Load()), orelse=Name(id='c', ctx=Load())))"},
118+
{"a, b = *a", "exec", "Module(body=[Assign(targets=[Tuple(elts=[Name(id='a', ctx=Store()), Name(id='b', ctx=Store())], ctx=Store())], value=Starred(value=Name(id='a', ctx=Load()), ctx=Load()))])"},
117119
{"a==b", "eval", "Expression(body=Compare(left=Name(id='a', ctx=Load()), ops=[Eq()], comparators=[Name(id='b', ctx=Load())]))"},
118120
{"a!=b", "eval", "Expression(body=Compare(left=Name(id='a', ctx=Load()), ops=[NotEq()], comparators=[Name(id='b', ctx=Load())]))"},
119121
{"a<b", "eval", "Expression(body=Compare(left=Name(id='a', ctx=Load()), ops=[Lt()], comparators=[Name(id='b', ctx=Load())]))"},

parser/make_grammar_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
("a+b-c/d//e%f", "eval"),
114114
("a+b-c/d//e%f**g", "eval"),
115115
("a+b-c/d//e%f**g|h&i^k<<l>>m", "eval"),
116+
("a if b else c", "eval"),
116117

117118
("a==b", "eval"),
118119
("a!=b", "eval"),
@@ -335,6 +336,7 @@
335336
("a = b = c", "exec"),
336337
("a, b = 1, 2", "exec"),
337338
("a, b = c, d = 1, 2", "exec"),
339+
("a, b = *a", "exec"),
338340

339341
# lambda
340342
("lambda: a", "eval"),

0 commit comments

Comments
 (0)