Skip to content

Commit 3429d35

Browse files
authored
Only wrap necessary parts of type aliases in forward annotations (#2548)
1 parent 599def0 commit 3429d35

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pydantic_ai_slim/pydantic_ai/tools.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
ToolParams = ParamSpec('ToolParams', default=...)
3232
"""Retrieval function param spec."""
3333

34-
SystemPromptFunc = Union[
34+
SystemPromptFunc: TypeAlias = Union[
3535
Callable[[RunContext[AgentDepsT]], str],
3636
Callable[[RunContext[AgentDepsT]], Awaitable[str]],
3737
Callable[[], str],
@@ -42,25 +42,25 @@
4242
Usage `SystemPromptFunc[AgentDepsT]`.
4343
"""
4444

45-
ToolFuncContext = Callable[Concatenate[RunContext[AgentDepsT], ToolParams], Any]
45+
ToolFuncContext: TypeAlias = Callable[Concatenate[RunContext[AgentDepsT], ToolParams], Any]
4646
"""A tool function that takes `RunContext` as the first argument.
4747
4848
Usage `ToolContextFunc[AgentDepsT, ToolParams]`.
4949
"""
50-
ToolFuncPlain = Callable[ToolParams, Any]
50+
ToolFuncPlain: TypeAlias = Callable[ToolParams, Any]
5151
"""A tool function that does not take `RunContext` as the first argument.
5252
5353
Usage `ToolPlainFunc[ToolParams]`.
5454
"""
55-
ToolFuncEither = Union[ToolFuncContext[AgentDepsT, ToolParams], ToolFuncPlain[ToolParams]]
55+
ToolFuncEither: TypeAlias = Union[ToolFuncContext[AgentDepsT, ToolParams], ToolFuncPlain[ToolParams]]
5656
"""Either kind of tool function.
5757
5858
This is just a union of [`ToolFuncContext`][pydantic_ai.tools.ToolFuncContext] and
5959
[`ToolFuncPlain`][pydantic_ai.tools.ToolFuncPlain].
6060
6161
Usage `ToolFuncEither[AgentDepsT, ToolParams]`.
6262
"""
63-
ToolPrepareFunc: TypeAlias = 'Callable[[RunContext[AgentDepsT], ToolDefinition], Awaitable[ToolDefinition | None]]'
63+
ToolPrepareFunc: TypeAlias = Callable[[RunContext[AgentDepsT], 'ToolDefinition'], Awaitable['ToolDefinition | None']]
6464
"""Definition of a function that can prepare a tool definition at call time.
6565
6666
See [tool docs](../tools.md#tool-prepare) for more information.
@@ -88,9 +88,9 @@ def hitchhiker(ctx: RunContext[int], answer: str) -> str:
8888
Usage `ToolPrepareFunc[AgentDepsT]`.
8989
"""
9090

91-
ToolsPrepareFunc: TypeAlias = (
92-
'Callable[[RunContext[AgentDepsT], list[ToolDefinition]], Awaitable[list[ToolDefinition] | None]]'
93-
)
91+
ToolsPrepareFunc: TypeAlias = Callable[
92+
[RunContext[AgentDepsT], list['ToolDefinition']], Awaitable['list[ToolDefinition] | None']
93+
]
9494
"""Definition of a function that can prepare the tool definition of all tools for each step.
9595
This is useful if you want to customize the definition of multiple tools or you want to register
9696
a subset of tools for a given step.
@@ -118,7 +118,7 @@ async def turn_on_strict_if_openai(
118118
Usage `ToolsPrepareFunc[AgentDepsT]`.
119119
"""
120120

121-
DocstringFormat = Literal['google', 'numpy', 'sphinx', 'auto']
121+
DocstringFormat: TypeAlias = Literal['google', 'numpy', 'sphinx', 'auto']
122122
"""Supported docstring formats.
123123
124124
* `'google'` — [Google-style](https://google.github.io/styleguide/pyguide.html#381-docstrings) docstrings.

0 commit comments

Comments
 (0)