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 =
38893889 in
38903890 let value =
38913891 match value with
3892- | Expression. BinaryOperator { operator = BinaryOperator. BitOr ; left; right; origin = _ } ->
3892+ | Expression. BinaryOperator { operator = BinaryOperator. BitOr ; left; right; origin } ->
38933893 let indices =
38943894 [left; right]
38953895 (* Recursively transform them into `typing.Union[...]` form *)
@@ -3899,6 +3899,7 @@ let replace_union_shorthand_in_annotation_expression =
38993899 |> List. rev
39003900 in
39013901 let index = { Node. value = Expression. Tuple indices; location } in
3902+ let origin = Some (Origin. create ?base:origin ~location Origin.UnionShorthand ) in
39023903 Expression. Subscript
39033904 {
39043905 base =
@@ -3910,11 +3911,11 @@ let replace_union_shorthand_in_annotation_expression =
39103911 {
39113912 base = { Node. location; value = Name (Name. Identifier " typing" ) };
39123913 attribute = " Union" ;
3913- origin = None ;
3914+ origin;
39143915 });
39153916 };
39163917 index;
3917- origin = None ;
3918+ origin;
39183919 }
39193920 | Subscript { Subscript. base; index; origin } ->
39203921 Subscript { base; index = transform_expression index; origin }
Original file line number Diff line number Diff line change @@ -1179,6 +1179,7 @@ and Origin : sig
11791179 | InGetItem (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
11801180 | InGetItemEq (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
11811181 | 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 *)
11821183 | Negate (* `if cond:` is turned into `assert(cond)` and `assert(not cond)` *)
11831184 | NegateIs (* `not(a is not b)` is turned into `a is b` *)
11841185 | NegateIsNot (* `not(a is b)` is turned into `a is not b` *)
@@ -1287,6 +1288,7 @@ end = struct
12871288 | InGetItem
12881289 | InGetItemEq
12891290 | Slice
1291+ | UnionShorthand
12901292 | Negate
12911293 | NegateIs
12921294 | NegateIsNot
Original file line number Diff line number Diff line change @@ -428,6 +428,7 @@ and Origin : sig
428428 | InGetItem (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
429429 | InGetItemEq (* `e in l` can be turned into `l.__getitem__(0).__eq__(e)` *)
430430 | 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 *)
431432 | Negate (* `if cond:` is turned into `assert(cond)` and `assert(not cond)` *)
432433 | NegateIs (* `not(a is not b)` is turned into `a is b` *)
433434 | NegateIsNot (* `not(a is b)` is turned into `a is not b` *)
You can’t perform that action at this time.
0 commit comments