MCPcopy
hub / github.com/pydantic/pydantic / generate_arguments_schema

Function generate_arguments_schema

pydantic/experimental/arguments_schema.py:14–44  ·  view source on GitHub ↗

Generate the schema for the arguments of a function. Args: func: The function to generate the schema for. schema_type: The type of schema to generate. parameters_callback: A callable that will be invoked for each parameter. The callback should take three requ

(
    func: Callable[..., Any],
    schema_type: Literal['arguments', 'arguments-v3'] = 'arguments-v3',
    parameters_callback: Callable[[int, str, Any], Literal['skip'] | None] | None = None,
    config: ConfigDict | None = None,
)

Source from the content-addressed store, hash-verified

12
13
14def generate_arguments_schema(
15 func: Callable[..., Any],
16 schema_type: Literal['arguments', 'arguments-v3'] = 'arguments-v3',
17 parameters_callback: Callable[[int, str, Any], Literal['skip'] | None] | None = None,
18 config: ConfigDict | None = None,
19) -> CoreSchema:
20 """Generate the schema for the arguments of a function.
21
22 Args:
23 func: The function to generate the schema for.
24 schema_type: The type of schema to generate.
25 parameters_callback: A callable that will be invoked for each parameter. The callback
26 should take three required arguments: the index, the name and the type annotation
27 (or [`Parameter.empty`][inspect.Parameter.empty] if not annotated) of the parameter.
28 The callback can optionally return `'skip'`, so that the parameter gets excluded
29 from the resulting schema.
30 config: The configuration to use.
31
32 Returns:
33 The generated schema.
34 """
35 generate_schema = _generate_schema.GenerateSchema(
36 _config.ConfigWrapper(config),
37 ns_resolver=_namespace_utils.NsResolver(namespaces_tuple=_namespace_utils.ns_for_function(func)),
38 )
39
40 if schema_type == 'arguments':
41 schema = generate_schema._arguments_schema(func, parameters_callback) # pyright: ignore[reportArgumentType]
42 else:
43 schema = generate_schema._arguments_v3_schema(func, parameters_callback) # pyright: ignore[reportArgumentType]
44 return generate_schema.clean_schema(schema)

Calls 3

_arguments_schemaMethod · 0.95
_arguments_v3_schemaMethod · 0.95
clean_schemaMethod · 0.95