@@ -96,16 +96,20 @@ def function_schema( # noqa: C901
96
96
config = ConfigDict (title = function .__name__ , use_attribute_docstrings = True )
97
97
config_wrapper = ConfigWrapper (config )
98
98
gen_schema = _generate_schema .GenerateSchema (config_wrapper )
99
+ errors : list [str ] = []
99
100
100
- sig = signature (function )
101
+ try :
102
+ sig = signature (function )
103
+ except ValueError as e :
104
+ errors .append (str (e ))
105
+ sig = signature (lambda : None )
101
106
102
107
type_hints = _typing_extra .get_function_type_hints (function )
103
108
104
109
var_kwargs_schema : core_schema .CoreSchema | None = None
105
110
fields : dict [str , core_schema .TypedDictField ] = {}
106
111
positional_fields : list [str ] = []
107
112
var_positional_field : str | None = None
108
- errors : list [str ] = []
109
113
decorators = _decorators .DecoratorInfos ()
110
114
111
115
description , field_descriptions = doc_descriptions (function , sig , docstring_format = docstring_format )
@@ -235,14 +239,19 @@ def _takes_ctx(function: TargetFunc[P, R]) -> TypeIs[WithCtx[P, R]]:
235
239
Returns:
236
240
`True` if the function takes a `RunContext` as first argument, `False` otherwise.
237
241
"""
238
- sig = signature (function )
242
+ try :
243
+ sig = signature (function )
244
+ except ValueError : # pragma: no cover
245
+ return False # pragma: no cover
239
246
try :
240
247
first_param_name = next (iter (sig .parameters .keys ()))
241
248
except StopIteration :
242
249
return False
243
250
else :
244
251
type_hints = _typing_extra .get_function_type_hints (function )
245
- annotation = type_hints [first_param_name ]
252
+ annotation = type_hints .get (first_param_name )
253
+ if annotation is None :
254
+ return False # pragma: no cover
246
255
return True is not sig .empty and _is_call_ctx (annotation )
247
256
248
257
0 commit comments