1- from typing import Any , Callable , Optional , Type
1+ from typing import Any , Callable , Optional , TypeVar
22
33from fhirpathpy .engine import do_eval
44from fhirpathpy .engine .invocations .constants import constants
@@ -128,13 +128,13 @@ def compile(path, model=None, options=None):
128128 return set_paths (apply_parsed_path , parsedPath = parse (path ), model = model , options = options )
129129
130130
131- type ResourceType = Any
132131type ContextType = Optional [dict ]
133-
132+ InputType = TypeVar ('InputType' )
133+ OutputType = TypeVar ('OutputType' )
134134
135135def compile_as_array (
136- expression : str , input_type : Type , output_type : Type
137- ) -> Callable [[Any ], Any ]:
136+ expression : str , input_type : type [ InputType ] , output_type : type [ OutputType ]
137+ ) -> Callable [[InputType , ContextType ], OutputType ]:
138138 path_fn = compile (expression )
139139
140140 def fn (resource : input_type , context : ContextType = None ) -> list [output_type ]:
@@ -146,8 +146,8 @@ def fn(resource: input_type, context: ContextType = None) -> list[output_type]:
146146
147147
148148def compile_as_first (
149- expression : str , input_type : Type , output_type : Type
150- ) -> Callable [[Any ], Any ]:
149+ expression : str , input_type : type [ InputType ] , output_type : type [ OutputType ]
150+ ) -> Callable [[InputType , ContextType ], OutputType ]:
151151 path_fn = compile (expression )
152152
153153 def fn (resource : input_type , context : ContextType = None ) -> output_type :
@@ -158,7 +158,7 @@ def fn(resource: input_type, context: ContextType = None) -> output_type:
158158 return fn
159159
160160
161- def _validate_and_convert_resource (resource : ResourceType , input_type : Type ) -> dict :
161+ def _validate_and_convert_resource (resource : Any , input_type : type [ InputType ] ) -> dict :
162162 if isinstance (resource , input_type ):
163163 if isinstance (resource , dict ):
164164 return resource
@@ -170,7 +170,7 @@ def _validate_and_convert_resource(resource: ResourceType, input_type: Type) ->
170170 raise Exception (f"Resource type is { type (resource )} , expected { input_type } " )
171171
172172
173- def _format_result (result : list , output_type : Type , is_first = False ) -> Any :
173+ def _format_result (result : list , output_type : type [ OutputType ] , is_first = False ) -> Any :
174174 if isinstance (result , list ):
175175 if is_first :
176176 if len (result ) > 0 :
0 commit comments