File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -1207,7 +1207,7 @@ def parse_dict_or_set_expr(self) -> Node:
1207
1207
items = List [Tuple [Node , Node ]]()
1208
1208
self .expect ('{' )
1209
1209
while self .current_str () != '}' and not self .eol ():
1210
- key = self .parse_expression (precedence ['<if >' ])
1210
+ key = self .parse_expression (precedence ['<for >' ])
1211
1211
if self .current_str () in [',' , '}' ] and items == []:
1212
1212
return self .parse_set_expr (key )
1213
1213
elif self .current_str () == 'for' and items == []:
Original file line number Diff line number Diff line change @@ -3086,3 +3086,34 @@ MypyFile:1(
3086
3086
x
3087
3087
IntExpr(1))
3088
3088
VarArg)))
3089
+
3090
+ [case testConditionalExpressionInSetComprehension]
3091
+ { 1 if x else 2 for x in y }
3092
+ [out]
3093
+ MypyFile:1(
3094
+ ExpressionStmt:1(
3095
+ SetComprehension:1(
3096
+ GeneratorExpr:1(
3097
+ ConditionalExpr:1(
3098
+ Condition(
3099
+ NameExpr(x))
3100
+ IntExpr(1)
3101
+ IntExpr(2))
3102
+ NameExpr(x)
3103
+ NameExpr(y)))))
3104
+
3105
+ [case testConditionalExpressionInListComprehension]
3106
+ a = [ 1 if x else 2 for x in y ]
3107
+ [out]
3108
+ MypyFile:1(
3109
+ AssignmentStmt:1(
3110
+ NameExpr(a)
3111
+ ListComprehension:1(
3112
+ GeneratorExpr:1(
3113
+ ConditionalExpr:1(
3114
+ Condition(
3115
+ NameExpr(x))
3116
+ IntExpr(1)
3117
+ IntExpr(2))
3118
+ NameExpr(x)
3119
+ NameExpr(y)))))
You can’t perform that action at this time.
0 commit comments