2828from elementpath .collations import UNICODE_COLLATION_BASE_URI , UNICODE_CODEPOINT_COLLATION
2929from elementpath .xpath_tokens import XPathToken , ProxyToken , XPathFunction , \
3030 XPathConstructor , SchemaConstructor , ExternalFunction
31- from elementpath .sequence_types import is_sequence_type , match_sequence_type
31+ from elementpath .sequence_types import get_function_signatures , is_sequence_type , \
32+ match_sequence_type
3233from elementpath .schema_proxy import AbstractSchemaProxy
3334from elementpath .xpath1 import XPath1Parser
3435
@@ -274,7 +275,7 @@ def bind(func: Callable[..., Any]) -> Callable[..., Any]:
274275 return func
275276 return bind
276277
277- def dynamic_register (self , symbol : str , class_name : str , ** kwargs : Any ) \
278+ def _register (self , symbol : str , class_name : str , ** kwargs : Any ) \
278279 -> type [ta .XPathTokenType ]:
279280 """
280281 Register/update a token class in the symbol table of a parser instance.
@@ -328,7 +329,7 @@ def schema_constructor(self, atomic_type_name: str, bp: int = 90) -> type[XPathF
328329 'lbp' : bp ,
329330 'rbp' : bp ,
330331 }
331- return cast (type [XPathFunction ], self .dynamic_register (symbol , class_name , ** kwargs ))
332+ return cast (type [XPathFunction ], self ._register (symbol , class_name , ** kwargs ))
332333
333334 def external_function (self ,
334335 callback : Callable [..., Any ],
@@ -364,27 +365,7 @@ def external_function(self,
364365 namespace = XPATH_FUNCTIONS_NAMESPACE
365366 qname = QName (XPATH_FUNCTIONS_NAMESPACE , f'fn:{ symbol } ' )
366367
367- function_signatures : dict [tuple [QName , int ], str ] = {}
368- if sequence_types :
369- if nargs is None :
370- assert len (sequence_types ) == 1
371- function_signatures [(qname , 0 )] = f'function() as { sequence_types [0 ]} '
372- elif isinstance (nargs , int ):
373- assert len (sequence_types ) == nargs + 1
374- function_signatures [(qname , nargs )] = 'function({}) as {}' .format (
375- ', ' .join (sequence_types [:- 1 ]), sequence_types [- 1 ]
376- )
377- elif nargs [1 ] is None :
378- assert len (sequence_types ) == nargs [0 ] + 1
379- function_signatures [(qname , nargs [0 ])] = 'function({}, ...) as {}' .format (
380- ', ' .join (sequence_types [:- 1 ]), sequence_types [- 1 ]
381- )
382- else :
383- assert len (sequence_types ) == nargs [1 ] + 1
384- for arity in range (nargs [0 ], nargs [1 ] + 1 ):
385- function_signatures [(qname , arity )] = 'function({}) as {}' .format (
386- ', ' .join (sequence_types [:arity ]), sequence_types [- 1 ]
387- )
368+ function_signatures = get_function_signatures (qname , nargs , sequence_types )
388369
389370 if qname .expanded_name in self .symbol_table :
390371 msg = f'function { qname .qname !r} is already registered'
@@ -414,7 +395,7 @@ def external_function(self,
414395 'lbp' : bp ,
415396 'rbp' : bp ,
416397 }
417- self .dynamic_register (symbol , class_name , ** kwargs )
398+ self ._register (symbol , class_name , ** kwargs )
418399
419400 class_name = f'{ upper_camel_case (qname .qname )} ExternalFunction'
420401 kwargs = {
@@ -428,7 +409,7 @@ def external_function(self,
428409 'sequence_types' : sequence_types ,
429410 'callback' : staticmethod (callback ),
430411 }
431- token_class = self .dynamic_register (symbol , class_name , ** kwargs )
412+ token_class = self ._register (symbol , class_name , ** kwargs )
432413
433414 if function_signatures :
434415 # Register function signatures
0 commit comments