Skip to content

Commit 5bbe2da

Browse files
authored
Merge pull request RustPython#2350 from isidentical/issue-2349
Handle raw yield expressions as RHS for augmented/annotated assignments
2 parents 28b5fe8 + f2ba412 commit 5bbe2da

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Lib/test/test_grammar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,7 @@ def test_var_annot_simple_exec(self):
461461
# exec('X: str', {}, CNS2())
462462
# self.assertEqual(nonloc_ns['__annotations__']['x'], str)
463463

464-
# TODO: RUSTPYTHON
465-
@unittest.expectedFailure
464+
466465
def test_var_annot_rhs(self):
467466
ns = {}
468467
exec('x: tuple = 1, 2', ns)

parser/src/python.lalrpop

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ExpressionStatement: ast::Statement = {
107107
}
108108
}
109109
},
110-
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestList> => {
110+
<location:@L> <target:TestOrStarExprList> <op:AugAssign> <rhs:TestListOrYieldExpr> => {
111111
ast::Statement {
112112
location,
113113
node: ast::StatementType::AugAssign {
@@ -117,23 +117,27 @@ ExpressionStatement: ast::Statement = {
117117
},
118118
}
119119
},
120-
<location:@L> <target:Test> ":" <annotation:Test> <rhs:("=" Test)?> => {
120+
<location:@L> <target:Test> ":" <annotation:Test> <rhs:AssignSuffix?> => {
121121
ast::Statement {
122122
location,
123123
node: ast::StatementType::AnnAssign {
124124
target: Box::new(target),
125125
annotation: Box::new(annotation),
126-
value: rhs.map(|e| e.1)
126+
value: rhs
127127
},
128128
}
129129
},
130130
};
131131

132132
AssignSuffix: ast::Expression = {
133-
"=" <e:TestList> => e,
134-
"=" <e:YieldExpr> => e,
133+
"=" <e:TestListOrYieldExpr> => e
135134
};
136135

136+
TestListOrYieldExpr: ast::Expression = {
137+
TestList,
138+
YieldExpr
139+
}
140+
137141
TestOrStarExprList: ast::Expression = {
138142
<location:@L> <elements:OneOrMore<TestOrStarExpr>> <comma:","?> => {
139143
if elements.len() == 1 && comma.is_none() {

0 commit comments

Comments
 (0)