@@ -457,7 +457,7 @@ def __edgeql_expr__(self, *, ctx: ScopeContext) -> str:
457457 rexpr = item ,
458458 type_ = SchemaPath ("std" , "bool" ),
459459 )
460- return f"FILTER { edgeql (fexpr , ctx = ctx )} "
460+ return f"FILTER { edgeql_exprstmt (fexpr , ctx = ctx )} "
461461
462462
463463class OrderDirection (_strenum .StrEnum ):
@@ -529,7 +529,7 @@ def __edgeql_expr__(self, *, ctx: ScopeContext) -> str:
529529 type_ = SchemaPath ("std" , "bool" ),
530530 )
531531
532- return f"ORDER BY { edgeql (dexpr , ctx = ctx )} "
532+ return f"ORDER BY { edgeql_exprstmt (dexpr , ctx = ctx )} "
533533
534534
535535@dataclass (kw_only = True , frozen = True )
@@ -548,7 +548,7 @@ def __edgeql_expr__(self, *, ctx: ScopeContext) -> str:
548548 if isinstance (self .limit , IntLiteral ) and self .limit .val == 1 :
549549 return "LIMIT 1"
550550 else :
551- clause = edgeql (self .limit , ctx = ctx )
551+ clause = edgeql_exprstmt (self .limit , ctx = ctx )
552552 return f"LIMIT { clause } "
553553
554554
@@ -564,7 +564,7 @@ def precedence(self) -> _edgeql.Precedence:
564564 return _edgeql .PRECEDENCE [_edgeql .Token .OFFSET ]
565565
566566 def __edgeql_expr__ (self , * , ctx : ScopeContext ) -> str :
567- return f"OFFSET { edgeql (self .offset , ctx = ctx )} "
567+ return f"OFFSET { edgeql_exprstmt (self .offset , ctx = ctx )} "
568568
569569
570570@dataclass (kw_only = True , frozen = True )
@@ -726,7 +726,7 @@ def _body_edgeql(self, ctx: ScopeContext) -> str:
726726
727727
728728@dataclass (kw_only = True , frozen = True )
729- class ForStmt (IteratorExpr ):
729+ class ForStmt (IteratorExpr , Stmt ):
730730 stmt : _edgeql .Token = _edgeql .Token .FOR
731731 iter_expr : Expr
732732 body : Expr
@@ -745,12 +745,19 @@ def subnodes(self) -> Iterable[Node]:
745745 return (self .iter_expr , self .body )
746746
747747 def _edgeql (self , ctx : ScopeContext ) -> str :
748+ ctx .bind (self .var )
748749 return (
749750 f"{ self .stmt } { edgeql (self .var , ctx = ctx )} IN "
750751 f"({ edgeql (self .iter_expr , ctx = ctx )} )\n "
751752 f"UNION ({ edgeql (self .body , ctx = ctx )} )"
752753 )
753754
755+ def _iteration_edgeql (self , ctx : ScopeContext ) -> str :
756+ raise AssertionError ('...' )
757+
758+ def _body_edgeql (self , ctx : ScopeContext ) -> str :
759+ raise AssertionError ('...' )
760+
754761
755762class Splat (_strenum .StrEnum ):
756763 STAR = "*"
@@ -908,6 +915,17 @@ def get_object_type_splat(cls: type[GelTypeMetadata]) -> Shape:
908915 return shape
909916
910917
918+ def edgeql_exprstmt (
919+ source : ExprCompatible ,
920+ * ,
921+ ctx : ScopeContext ,
922+ ) -> str :
923+ res = edgeql (source , ctx = ctx )
924+ if isinstance (source , Stmt ):
925+ res = f'({ res } )'
926+ return res
927+
928+
911929def toplevel_edgeql (
912930 x : ExprCompatible ,
913931 * ,
0 commit comments