@@ -262,6 +262,28 @@ end = struct
262262 | _ -> List. compare Argument. location_insensitive_compare left.arguments right.arguments
263263end
264264
265+ and Await : sig
266+ type t = {
267+ operand : Expression .t ;
268+ (* If this AST node was created from lowering down another AST node (for instance, `a + b` is
269+ turned into `a.__add__(b)`), `origin` stores the location of the original AST node and the
270+ reason for lowering it. *)
271+ origin : Origin .t option ;
272+ }
273+ [@@ deriving equal , compare , sexp , show , hash , to_yojson ]
274+
275+ val location_insensitive_compare : t -> t -> int
276+ end = struct
277+ type t = {
278+ operand : Expression .t ;
279+ origin : Origin .t option ;
280+ }
281+ [@@ deriving equal , compare , sexp , show , hash , to_yojson ]
282+
283+ let location_insensitive_compare left right =
284+ Expression. location_insensitive_compare left.operand right.operand
285+ end
286+
265287and ComparisonOperator : sig
266288 type operator =
267289 | Equals
@@ -1147,8 +1169,10 @@ and Origin : sig
11471169 | SubscriptGetItem (* `d[a]` is turned into `d.__getitem__(a)` *)
11481170 | ForIter (* `for e in l:` is turned into `l.__iter__().__next__()` *)
11491171 | ForNext (* `for e in l:` is turned into `l.__iter__().__next__()` *)
1172+ | ForAwait (* `for e in l:` might be turned into `await l.__iter__().__next__()` *)
11501173 | GeneratorIter (* `(e for e in l)` is turned into `l.__iter__().__next__()` *)
11511174 | GeneratorNext (* `(e for e in l)` is turned into `l.__iter__().__next__()` *)
1175+ | GeneratorAwait (* `(e for e in l)` might be turned into `await l.__iter__().__next__()` *)
11521176 | With (* `with e1 as e2` is turned into `e2 = e1.__enter__()` *)
11531177 | InContains (* `e in l` can be turned into `l.__contains__(e)` *)
11541178 | InIter (* `e in l` can be turned into `l.__iter__().__next__().__eq__(e)` *)
@@ -1253,8 +1277,10 @@ end = struct
12531277 | SubscriptGetItem
12541278 | ForIter
12551279 | ForNext
1280+ | ForAwait
12561281 | GeneratorIter
12571282 | GeneratorNext
1283+ | GeneratorAwait
12581284 | With
12591285 | InContains
12601286 | InIter
@@ -1368,7 +1394,7 @@ end
13681394
13691395and Expression : sig
13701396 type expression =
1371- | Await of t
1397+ | Await of Await . t
13721398 | BinaryOperator of BinaryOperator .t
13731399 | BooleanOperator of BooleanOperator .t
13741400 | Call of Call .t
@@ -1407,7 +1433,7 @@ and Expression : sig
14071433 val pp_type_param_list : Format .formatter -> TypeParam .t list -> unit
14081434end = struct
14091435 type expression =
1410- | Await of t
1436+ | Await of Await . t
14111437 | BinaryOperator of BinaryOperator .t
14121438 | BooleanOperator of BooleanOperator .t
14131439 | Call of Call .t
@@ -1439,7 +1465,7 @@ end = struct
14391465
14401466 let rec location_insensitive_compare_expression left right =
14411467 match left, right with
1442- | Await left , Await right -> location_insensitive_compare left right
1468+ | Await left , Await right -> Await. location_insensitive_compare left right
14431469 | BinaryOperator left , BinaryOperator right ->
14441470 BinaryOperator. location_insensitive_compare left right
14451471 | BooleanOperator left , BooleanOperator right ->
@@ -1700,7 +1726,7 @@ end = struct
17001726
17011727 and pp_expression formatter expression =
17021728 match expression with
1703- | Await expression -> Format. fprintf formatter " await %a" pp_expression_t expression
1729+ | Await { Await. operand; _ } -> Format. fprintf formatter " await %a" pp_expression_t operand
17041730 | BinaryOperator { BinaryOperator. left; operator; right; origin = _ } ->
17051731 Format. fprintf
17061732 formatter
@@ -1823,7 +1849,7 @@ end
18231849
18241850module Mapper = struct
18251851 type 'a t = {
1826- map_await : mapper :'a t -> location :Location .t -> Expression .t -> 'a ;
1852+ map_await : mapper :'a t -> location :Location .t -> Await .t -> 'a ;
18271853 map_binary_operator : mapper :'a t -> location :Location .t -> BinaryOperator .t -> 'a ;
18281854 map_boolean_operator : mapper :'a t -> location :Location .t -> BooleanOperator .t -> 'a ;
18291855 map_call : mapper :'a t -> location :Location .t -> Call .t -> 'a ;
@@ -1884,7 +1910,7 @@ module Mapper = struct
18841910 { Node. value; location }
18851911 =
18861912 match value with
1887- | Expression. Await expression -> map_await ~mapper ~location expression
1913+ | Expression. Await await -> map_await ~mapper ~location await
18881914 | Expression. BinaryOperator binary_operator ->
18891915 map_binary_operator ~mapper ~location binary_operator
18901916 | Expression. BooleanOperator boolean_operator ->
@@ -2006,7 +2032,9 @@ module Mapper = struct
20062032 default_map_substrings_with_location ~mapper ~map_location: Fn. id substrings
20072033
20082034
2009- let default_map_await ~mapper awaited = map ~mapper awaited
2035+ let default_map_await ~mapper { Await. operand; origin } =
2036+ { Await. operand = map ~mapper operand; origin }
2037+
20102038
20112039 let default_map_await_node ~mapper ~location awaited =
20122040 Node. create ~location (Expression. Await (default_map_await ~mapper awaited))
@@ -2530,7 +2558,7 @@ end
25302558
25312559module Folder = struct
25322560 type 'a t = {
2533- fold_await : folder :'a t -> state :'a -> location :Location .t -> Expression .t -> 'a ;
2561+ fold_await : folder :'a t -> state :'a -> location :Location .t -> Await .t -> 'a ;
25342562 fold_binary_operator : folder :'a t -> state :'a -> location :Location .t -> BinaryOperator .t -> 'a ;
25352563 fold_boolean_operator :
25362564 folder :'a t -> state :'a -> location :Location .t -> BooleanOperator .t -> 'a ;
@@ -2600,7 +2628,7 @@ module Folder = struct
26002628 { Node. value; location }
26012629 =
26022630 match value with
2603- | Expression. Await expression -> fold_await ~folder ~state ~location expression
2631+ | Expression. Await await -> fold_await ~folder ~state ~location await
26042632 | Expression. BinaryOperator binary_operator ->
26052633 fold_binary_operator ~folder ~state ~location binary_operator
26062634 | Expression. BooleanOperator boolean_operator ->
@@ -2740,7 +2768,7 @@ module Folder = struct
27402768 substrings
27412769
27422770
2743- let default_fold_await ~folder ~state awaited = fold ~folder ~state awaited
2771+ let default_fold_await ~folder ~state { Await. operand; origin = _ } = fold ~folder ~state operand
27442772
27452773 let default_fold_binary_operator
27462774 ~folder
@@ -2997,6 +3025,7 @@ let origin { Node.value; _ } =
29973025 | Expression. Subscript { Subscript. origin; _ } -> origin
29983026 | Expression. WalrusOperator { WalrusOperator. origin; _ } -> origin
29993027 | Expression. Slice { Slice. origin; _ } -> origin
3028+ | Expression. Await { Await. origin; _ } -> origin
30003029 | _ -> None
30013030
30023031
@@ -3560,6 +3589,9 @@ let remove_origins expression =
35603589 origin = None ;
35613590 }
35623591 in
3592+ let map_await ~mapper { Await. operand; origin = _ } =
3593+ { Await. operand = Mapper. map ~mapper operand; origin = None }
3594+ in
35633595 Mapper. map
35643596 ~mapper:
35653597 (Mapper. create_transformer
@@ -3572,5 +3604,6 @@ let remove_origins expression =
35723604 ~map_subscript
35733605 ~map_walrus_operator
35743606 ~map_slice
3607+ ~map_await
35753608 () )
35763609 expression
0 commit comments