1919import importlib .util
2020import inspect
2121import json
22- import sys
2322import typing
24- from typing import Any , Optional , Tuple
23+ from typing import (
24+ Any ,
25+ Optional ,
26+ Tuple ,
27+ )
2528
2629
2730def load_function_module (entrypoint_path : str , module_name : str = "function_module" ):
@@ -59,7 +62,7 @@ def get_function_callable(module):
5962 AttributeError: If module doesn't have a 'function' attribute
6063 """
6164 if not hasattr (module , "function" ):
62- raise AttributeError (f "Module does not have a 'function' callable" )
65+ raise AttributeError ("Module does not have a 'function' callable" )
6366 return module .function
6467
6568
@@ -108,7 +111,9 @@ def get_function_signature_types(
108111 return request_type , response_type , request_type_name , response_type_name
109112
110113
111- def inspect_function_types_static (entrypoint_path : str ) -> Tuple [Optional [str ], Optional [str ]]:
114+ def inspect_function_types_static (
115+ entrypoint_path : str ,
116+ ) -> Tuple [Optional [str ], Optional [str ]]:
112117 """Inspect function types using static AST parsing (no imports).
113118
114119 This parses the Python file without executing it, so it doesn't
@@ -121,7 +126,7 @@ def inspect_function_types_static(entrypoint_path: str) -> Tuple[Optional[str],
121126 Tuple of (request_type_name, response_type_name)
122127 """
123128 try :
124- with open (entrypoint_path , 'r' ) as f :
129+ with open (entrypoint_path , "r" ) as f :
125130 tree = ast .parse (f .read (), filename = entrypoint_path )
126131
127132 # Find the 'function' definition
@@ -132,7 +137,9 @@ def inspect_function_types_static(entrypoint_path: str) -> Tuple[Optional[str],
132137 if node .args .args and len (node .args .args ) > 0 :
133138 first_param = node .args .args [0 ]
134139 if first_param .annotation :
135- request_type_name = _get_type_name_from_ast (first_param .annotation )
140+ request_type_name = _get_type_name_from_ast (
141+ first_param .annotation
142+ )
136143
137144 # Get response type (return annotation)
138145 response_type_name = None
@@ -175,7 +182,7 @@ def _import_pydantic_model(entrypoint_path: str, type_name: str) -> Optional[Any
175182 The Pydantic model class, or None if not found
176183 """
177184 try :
178- with open (entrypoint_path , 'r' ) as f :
185+ with open (entrypoint_path , "r" ) as f :
179186 tree = ast .parse (f .read (), filename = entrypoint_path )
180187
181188 # Find where this type is imported from
@@ -344,12 +351,12 @@ def generate_test_json(entrypoint_path: str, output_path: str) -> None:
344351
345352 # Check if it's a Pydantic model
346353 if not hasattr (request_type , "model_fields" ):
347- raise ValueError (f "Request parameter type must be a Pydantic model" )
354+ raise ValueError ("Request parameter type must be a Pydantic model" )
348355
349356 # Generate sample data for ALL fields (use defaults where available)
350357 sample_data = _generate_model_sample_data (request_type )
351358 sample_instance = request_type (** sample_data )
352359
353360 # Write to file
354361 with open (output_path , "w" ) as f :
355- json .dump (sample_instance .model_dump (), f , indent = 2 )
362+ json .dump (sample_instance .model_dump (), f , indent = 2 )
0 commit comments