@@ -318,7 +318,7 @@ def set_children(self, children: List[FilterExpression]) -> None:
318318class InfixExpression (FilterExpression ):
319319 """A pair of expressions and a comparison or logical operator."""
320320
321- __slots__ = ("left" , "operator" , "right" )
321+ __slots__ = ("left" , "operator" , "right" , "logical" )
322322
323323 def __init__ (
324324 self ,
@@ -329,10 +329,11 @@ def __init__(
329329 self .left = left
330330 self .operator = operator
331331 self .right = right
332+ self .logical = operator in ("&&" , "||" )
332333 super ().__init__ ()
333334
334335 def __str__ (self ) -> str :
335- if self .operator in ( "&&" , "||" ) :
336+ if self .logical :
336337 return f"({ self .left } { self .operator } { self .right } )"
337338 return f"{ self .left } { self .operator } { self .right } "
338339
@@ -346,22 +347,22 @@ def __eq__(self, other: object) -> bool:
346347
347348 def evaluate (self , context : FilterContext ) -> bool :
348349 left = self .left .evaluate (context )
349- if isinstance (left , NodeList ) and len (left ) == 1 :
350+ if not self . logical and isinstance (left , NodeList ) and len (left ) == 1 :
350351 left = left [0 ].obj
351352
352353 right = self .right .evaluate (context )
353- if isinstance (right , NodeList ) and len (right ) == 1 :
354+ if not self . logical and isinstance (right , NodeList ) and len (right ) == 1 :
354355 right = right [0 ].obj
355356
356357 return context .env .compare (left , self .operator , right )
357358
358359 async def evaluate_async (self , context : FilterContext ) -> bool :
359360 left = await self .left .evaluate_async (context )
360- if isinstance (left , NodeList ) and len (left ) == 1 :
361+ if not self . logical and isinstance (left , NodeList ) and len (left ) == 1 :
361362 left = left [0 ].obj
362363
363364 right = await self .right .evaluate_async (context )
364- if isinstance (right , NodeList ) and len (right ) == 1 :
365+ if not self . logical and isinstance (right , NodeList ) and len (right ) == 1 :
365366 right = right [0 ].obj
366367
367368 return context .env .compare (left , self .operator , right )
0 commit comments