@@ -381,6 +381,28 @@ def _to_pb(self):
381
381
class FilterCondition (Function ):
382
382
"""Filters the given data in some way."""
383
383
384
+ def __init__ (
385
+ self ,
386
+ * args ,
387
+ use_infix_repr :bool = True ,
388
+ ** kwargs ,
389
+ ):
390
+ self ._use_infix_repr = use_infix_repr
391
+ super ().__init__ (* args , ** kwargs )
392
+
393
+ def __repr__ (self ):
394
+ """
395
+ Most FilterConditions can be triggered infix. Eg: Field.of('age').gte(18).
396
+
397
+ Display them this way in the repr string where possible
398
+ """
399
+ if self ._use_infix_repr :
400
+ if len (self .params ) == 1 :
401
+ return f"{ self .params [0 ]!r} .{ self .name } ()"
402
+ elif len (self .params ) == 2 :
403
+ return f"{ self .params [0 ]!r} .{ self .name } ({ self .params [1 ]!r} )"
404
+ return super ().__repr__ ()
405
+
384
406
@staticmethod
385
407
def _from_query_filter_pb (filter_pb , client ):
386
408
if isinstance (filter_pb , Query_pb .CompositeFilter ):
@@ -447,7 +469,7 @@ def _from_query_filter_pb(filter_pb, client):
447
469
448
470
class And (FilterCondition ):
449
471
def __init__ (self , * conditions : "FilterCondition" ):
450
- super ().__init__ ("and" , conditions )
472
+ super ().__init__ ("and" , conditions , use_infix_repr = False )
451
473
452
474
453
475
class ArrayContains (FilterCondition ):
@@ -531,11 +553,11 @@ class Not(FilterCondition):
531
553
"""Represents the logical NOT of a filter condition."""
532
554
533
555
def __init__ (self , condition : Expr ):
534
- super ().__init__ ("not" , [condition ])
556
+ super ().__init__ ("not" , [condition ], use_infix_repr = False )
535
557
536
558
537
559
class Or (FilterCondition ):
538
560
"""Represents the logical OR of multiple filter conditions."""
539
561
540
562
def __init__ (self , * conditions : "FilterCondition" ):
541
- super ().__init__ ("or" , conditions )
563
+ super ().__init__ ("or" , conditions , use_infix_repr = False )
0 commit comments