@@ -529,11 +529,9 @@ def __str__(self) -> str:
529529 return "@" + str (self .path )[1 :]
530530
531531 def evaluate (self , context : FilterContext ) -> object :
532- if isinstance (context .current , str ): # TODO: refactor
533- if self .path .empty ():
534- return context .current
535- return NodeList ()
536- if not isinstance (context .current , (Sequence , Mapping )):
532+ if isinstance (context .current , str ) or not isinstance (
533+ context .current , (Sequence , Mapping )
534+ ):
537535 if self .path .empty ():
538536 return context .current
539537 return NodeList ()
@@ -546,11 +544,9 @@ def evaluate(self, context: FilterContext) -> object:
546544 )
547545
548546 async def evaluate_async (self , context : FilterContext ) -> object :
549- if isinstance (context .current , str ): # TODO: refactor
550- if self .path .empty ():
551- return context .current
552- return NodeList ()
553- if not isinstance (context .current , (Sequence , Mapping )):
547+ if isinstance (context .current , str ) or not isinstance (
548+ context .current , (Sequence , Mapping )
549+ ):
554550 if self .path .empty ():
555551 return context .current
556552 return NodeList ()
@@ -660,15 +656,19 @@ def evaluate(self, context: FilterContext) -> object:
660656 try :
661657 func = context .env .function_extensions [self .name ]
662658 except KeyError :
663- return UNDEFINED # TODO: should probably raise an exception
659+ # This can only happen if the environment's function register has been
660+ # changed since the query was parsed.
661+ return UNDEFINED
664662 args = [arg .evaluate (context ) for arg in self .args ]
665663 return func (* self ._unpack_node_lists (func , args ))
666664
667665 async def evaluate_async (self , context : FilterContext ) -> object :
668666 try :
669667 func = context .env .function_extensions [self .name ]
670668 except KeyError :
671- return UNDEFINED # TODO: should probably raise an exception
669+ # This can only happen if the environment's function register has been
670+ # changed since the query was parsed.
671+ return UNDEFINED
672672 args = [await arg .evaluate_async (context ) for arg in self .args ]
673673 return func (* self ._unpack_node_lists (func , args ))
674674
0 commit comments