File tree Expand file tree Collapse file tree 3 files changed +7
-3
lines changed Expand file tree Collapse file tree 3 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -3889,7 +3889,7 @@ let replace_union_shorthand_in_annotation_expression =
3889
3889
in
3890
3890
let value =
3891
3891
match value with
3892
- | Expression. BinaryOperator { operator = BinaryOperator. BitOr ; left; right; origin = _ } ->
3892
+ | Expression. BinaryOperator { operator = BinaryOperator. BitOr ; left; right; origin } ->
3893
3893
let indices =
3894
3894
[left; right]
3895
3895
(* Recursively transform them into `typing.Union[...]` form *)
@@ -3899,6 +3899,7 @@ let replace_union_shorthand_in_annotation_expression =
3899
3899
|> List. rev
3900
3900
in
3901
3901
let index = { Node. value = Expression. Tuple indices; location } in
3902
+ let origin = Some (Origin. create ?base:origin ~location Origin.UnionShorthand ) in
3902
3903
Expression. Subscript
3903
3904
{
3904
3905
base =
@@ -3910,11 +3911,11 @@ let replace_union_shorthand_in_annotation_expression =
3910
3911
{
3911
3912
base = { Node. location; value = Name (Name. Identifier " typing" ) };
3912
3913
attribute = " Union" ;
3913
- origin = None ;
3914
+ origin;
3914
3915
});
3915
3916
};
3916
3917
index;
3917
- origin = None ;
3918
+ origin;
3918
3919
}
3919
3920
| Subscript { Subscript. base; index; origin } ->
3920
3921
Subscript { base; index = transform_expression index; origin }
Original file line number Diff line number Diff line change @@ -1179,6 +1179,7 @@ and Origin : sig
1179
1179
| InGetItem (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
1180
1180
| InGetItemEq (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
1181
1181
| Slice (* `1:2` is turned into `slice(1,2,None)` *)
1182
+ | UnionShorthand (* `a | b` is turned into `typing.Union[a, b]` when in typing context *)
1182
1183
| Negate (* `if cond:` is turned into `assert(cond)` and `assert(not cond)` *)
1183
1184
| NegateIs (* `not(a is not b)` is turned into `a is b` *)
1184
1185
| NegateIsNot (* `not(a is b)` is turned into `a is not b` *)
@@ -1287,6 +1288,7 @@ end = struct
1287
1288
| InGetItem
1288
1289
| InGetItemEq
1289
1290
| Slice
1291
+ | UnionShorthand
1290
1292
| Negate
1291
1293
| NegateIs
1292
1294
| NegateIsNot
Original file line number Diff line number Diff line change @@ -428,6 +428,7 @@ and Origin : sig
428
428
| InGetItem (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
429
429
| InGetItemEq (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
430
430
| Slice (* `1:2` is turned into `slice(1,2,None)` *)
431
+ | UnionShorthand (* `a | b` is turned into `typing.Union[a, b]` when in typing context *)
431
432
| Negate (* `if cond:` is turned into `assert(cond)` and `assert(not cond)` *)
432
433
| NegateIs (* `not(a is not b)` is turned into `a is b` *)
433
434
| NegateIsNot (* `not(a is b)` is turned into `a is not b` *)
You can’t perform that action at this time.
0 commit comments