11import logging
2- from typing import get_origin
32
43from models_library .api_schemas_webserver import (
54 WEBSERVER_RPC_NAMESPACE ,
@@ -38,7 +37,7 @@ async def register_function(
3837 TypeAdapter (RPCMethodName ).validate_python ("register_function" ),
3938 function = function ,
4039 )
41- assert isinstance ( result , get_origin ( Function ) or Function ) # nosec
40+ TypeAdapter ( Function ). validate_python ( result ) # Validates the result as a Function
4241 return result
4342
4443
@@ -53,7 +52,7 @@ async def get_function(
5352 TypeAdapter (RPCMethodName ).validate_python ("get_function" ),
5453 function_id = function_id ,
5554 )
56- assert isinstance ( result , get_origin ( Function ) or Function ) # nosec
55+ TypeAdapter ( Function ). validate_python ( result )
5756 return result
5857
5958
@@ -68,7 +67,7 @@ async def get_function_input_schema(
6867 TypeAdapter (RPCMethodName ).validate_python ("get_function_input_schema" ),
6968 function_id = function_id ,
7069 )
71- assert isinstance ( result , FunctionInputSchema ) # nosec
70+ TypeAdapter ( FunctionInputSchema ). validate_python ( result )
7271 return result
7372
7473
@@ -83,7 +82,7 @@ async def get_function_output_schema(
8382 TypeAdapter (RPCMethodName ).validate_python ("get_function_output_schema" ),
8483 function_id = function_id ,
8584 )
86- assert isinstance ( result , FunctionOutputSchema ) # nosec
85+ TypeAdapter ( FunctionOutputSchema ). validate_python ( result )
8786 return result
8887
8988
@@ -118,7 +117,9 @@ async def list_functions(
118117 )
119118 )
120119 assert isinstance (result , tuple )
121- assert isinstance (result [0 ], list ) # nosec
120+ TypeAdapter (list [Function ]).validate_python (
121+ result [0 ]
122+ ) # Validates the result as a list of Functions
122123 assert isinstance (result [1 ], PageMetaInfoLimitOffset ) # nosec
123124 return result
124125
@@ -139,7 +140,9 @@ async def list_function_jobs(
139140 )
140141 )
141142 assert isinstance (result , tuple )
142- assert isinstance (result [0 ], list ) # nosec
143+ TypeAdapter (list [FunctionJob ]).validate_python (
144+ result [0 ]
145+ ) # Validates the result as a list of FunctionJobs
143146 assert isinstance (result [1 ], PageMetaInfoLimitOffset ) # nosec
144147 return result
145148
@@ -160,7 +163,9 @@ async def list_function_job_collections(
160163 )
161164 )
162165 assert isinstance (result , tuple )
163- assert isinstance (result [0 ], list ) # nosec
166+ TypeAdapter (list [FunctionJobCollection ]).validate_python (
167+ result [0 ]
168+ ) # Validates the result as a list of FunctionJobCollections
164169 assert isinstance (result [1 ], PageMetaInfoLimitOffset ) # nosec
165170 return result
166171
@@ -178,7 +183,9 @@ async def run_function(
178183 function_id = function_id ,
179184 inputs = inputs ,
180185 )
181- assert isinstance (result , get_origin (FunctionJob ) or FunctionJob ) # nosec
186+ TypeAdapter (FunctionJob ).validate_python (
187+ result
188+ ) # Validates the result as a FunctionJob
182189 return result
183190
184191
@@ -193,7 +200,9 @@ async def register_function_job(
193200 TypeAdapter (RPCMethodName ).validate_python ("register_function_job" ),
194201 function_job = function_job ,
195202 )
196- assert isinstance (result , get_origin (FunctionJob ) or FunctionJob ) # nosec
203+ TypeAdapter (FunctionJob ).validate_python (
204+ result
205+ ) # Validates the result as a FunctionJob
197206 return result
198207
199208
@@ -208,7 +217,8 @@ async def get_function_job(
208217 TypeAdapter (RPCMethodName ).validate_python ("get_function_job" ),
209218 function_job_id = function_job_id ,
210219 )
211- assert isinstance (result , get_origin (FunctionJob ) or FunctionJob ) # nosec
220+
221+ TypeAdapter (FunctionJob ).validate_python (result )
212222 return result
213223
214224
@@ -242,7 +252,7 @@ async def find_cached_function_job(
242252 )
243253 if result is None :
244254 return None
245- assert isinstance ( result , get_origin ( FunctionJob ) or FunctionJob ) # nosec
255+ TypeAdapter ( FunctionJob ). validate_python ( result )
246256 return result
247257
248258
@@ -257,7 +267,7 @@ async def register_function_job_collection(
257267 TypeAdapter (RPCMethodName ).validate_python ("register_function_job_collection" ),
258268 function_job_collection = function_job_collection ,
259269 )
260- assert isinstance ( result , FunctionJobCollection ) # nosec
270+ TypeAdapter ( FunctionJobCollection ). validate_python ( result )
261271 return result
262272
263273
@@ -272,7 +282,7 @@ async def get_function_job_collection(
272282 TypeAdapter (RPCMethodName ).validate_python ("get_function_job_collection" ),
273283 function_job_collection_id = function_job_collection_id ,
274284 )
275- assert isinstance ( result , FunctionJobCollection ) # nosec
285+ TypeAdapter ( FunctionJobCollection ). validate_python ( result )
276286 return result
277287
278288
0 commit comments