Skip to content

Commit 10b7da6

Browse files
committed
more parens, drop an __eq__ optimization
1 parent dc2b57d commit 10b7da6

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

gel/_internal/_qb/_expressions.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

463463
class 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)
@@ -915,6 +915,17 @@ def get_object_type_splat(cls: type[GelTypeMetadata]) -> Shape:
915915
return shape
916916

917917

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+
918929
def toplevel_edgeql(
919930
x: ExprCompatible,
920931
*,

gel/_internal/_qb/_generics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ def __infix_op__(
316316
*,
317317
swapped: bool = False,
318318
) -> Any:
319-
if op == "__eq__" and operand is self:
320-
return True
321-
322319
# Check for None comparison and raise appropriate error
323320
if operand is None and op in {"__eq__", "__ne__"}:
324321
_raise_op_error(_Op.IS_NONE if op == "__eq__" else _Op.IS_NOT_NONE)

tests/test_qb.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,27 @@ def test_qb_for_01(self):
628628
{'Alice', 'Zoe', 'Billie', 'Dana', 'Cameron', 'Elsa'},
629629
)
630630

631+
res3 = self.client.query(
632+
default.User.filter(
633+
lambda u: std.for_(
634+
std.assert_exists(std.int64(0)),
635+
# HMMMMM
636+
lambda x: x == x,
637+
)
638+
)
639+
)
640+
self.assertEqual(len(res3), 6)
641+
642+
res4 = self.client.query(
643+
default.User.filter(
644+
lambda u: std.for_(
645+
u.name,
646+
lambda x: x == "Alice",
647+
)
648+
)
649+
)
650+
self.assertEqual(len(res4), 1)
651+
631652

632653
class TestQueryBuilderModify(tb.ModelTestCase):
633654
"""This test suite is for data manipulation using QB."""

0 commit comments

Comments
 (0)