@@ -381,6 +381,28 @@ def _to_pb(self):
381381class FilterCondition (Function ):
382382 """Filters the given data in some way."""
383383
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+
384406 @staticmethod
385407 def _from_query_filter_pb (filter_pb , client ):
386408 if isinstance (filter_pb , Query_pb .CompositeFilter ):
@@ -447,7 +469,7 @@ def _from_query_filter_pb(filter_pb, client):
447469
448470class And (FilterCondition ):
449471 def __init__ (self , * conditions : "FilterCondition" ):
450- super ().__init__ ("and" , conditions )
472+ super ().__init__ ("and" , conditions , use_infix_repr = False )
451473
452474
453475class ArrayContains (FilterCondition ):
@@ -531,11 +553,11 @@ class Not(FilterCondition):
531553 """Represents the logical NOT of a filter condition."""
532554
533555 def __init__ (self , condition : Expr ):
534- super ().__init__ ("not" , [condition ])
556+ super ().__init__ ("not" , [condition ], use_infix_repr = False )
535557
536558
537559class Or (FilterCondition ):
538560 """Represents the logical OR of multiple filter conditions."""
539561
540562 def __init__ (self , * conditions : "FilterCondition" ):
541- super ().__init__ ("or" , conditions )
563+ super ().__init__ ("or" , conditions , use_infix_repr = False )
0 commit comments