Skip to content

Commit f9d90aa

Browse files
authored
Raise consistent deprecation warnings (#2148)
1 parent 8862e6e commit f9d90aa

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pydantic_ai_slim/pydantic_ai/agent.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def __init__(
296296
if 'result_type' in _deprecated_kwargs:
297297
if output_type is not str: # pragma: no cover
298298
raise TypeError('`result_type` and `output_type` cannot be set at the same time.')
299-
warnings.warn('`result_type` is deprecated, use `output_type` instead', DeprecationWarning)
299+
warnings.warn('`result_type` is deprecated, use `output_type` instead', DeprecationWarning, stacklevel=2)
300300
output_type = _deprecated_kwargs.pop('result_type')
301301

302302
self.output_type = output_type
@@ -310,19 +310,23 @@ def __init__(
310310
warnings.warn(
311311
'`result_tool_name` is deprecated, use `output_type` with `ToolOutput` instead',
312312
DeprecationWarning,
313+
stacklevel=2,
313314
)
314315

315316
self._deprecated_result_tool_description = _deprecated_kwargs.pop('result_tool_description', None)
316317
if self._deprecated_result_tool_description is not None:
317318
warnings.warn(
318319
'`result_tool_description` is deprecated, use `output_type` with `ToolOutput` instead',
319320
DeprecationWarning,
321+
stacklevel=2,
320322
)
321323
result_retries = _deprecated_kwargs.pop('result_retries', None)
322324
if result_retries is not None:
323325
if output_retries is not None: # pragma: no cover
324326
raise TypeError('`output_retries` and `result_retries` cannot be set at the same time.')
325-
warnings.warn('`result_retries` is deprecated, use `max_result_retries` instead', DeprecationWarning)
327+
warnings.warn(
328+
'`result_retries` is deprecated, use `max_result_retries` instead', DeprecationWarning, stacklevel=2
329+
)
326330
output_retries = result_retries
327331

328332
default_output_mode = (
@@ -472,7 +476,7 @@ async def main():
472476
if 'result_type' in _deprecated_kwargs: # pragma: no cover
473477
if output_type is not str:
474478
raise TypeError('`result_type` and `output_type` cannot be set at the same time.')
475-
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning)
479+
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning, stacklevel=2)
476480
output_type = _deprecated_kwargs.pop('result_type')
477481

478482
_utils.validate_empty_kwargs(_deprecated_kwargs)
@@ -640,7 +644,7 @@ async def main():
640644
if 'result_type' in _deprecated_kwargs: # pragma: no cover
641645
if output_type is not str:
642646
raise TypeError('`result_type` and `output_type` cannot be set at the same time.')
643-
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning)
647+
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning, stacklevel=2)
644648
output_type = _deprecated_kwargs.pop('result_type')
645649

646650
_utils.validate_empty_kwargs(_deprecated_kwargs)
@@ -879,7 +883,7 @@ def run_sync(
879883
if 'result_type' in _deprecated_kwargs: # pragma: no cover
880884
if output_type is not str:
881885
raise TypeError('`result_type` and `output_type` cannot be set at the same time.')
882-
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning)
886+
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning, stacklevel=2)
883887
output_type = _deprecated_kwargs.pop('result_type')
884888

885889
_utils.validate_empty_kwargs(_deprecated_kwargs)
@@ -997,7 +1001,7 @@ async def main():
9971001
if 'result_type' in _deprecated_kwargs: # pragma: no cover
9981002
if output_type is not str:
9991003
raise TypeError('`result_type` and `output_type` cannot be set at the same time.')
1000-
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning)
1004+
warnings.warn('`result_type` is deprecated, use `output_type` instead.', DeprecationWarning, stacklevel=2)
10011005
output_type = _deprecated_kwargs.pop('result_type')
10021006

10031007
_utils.validate_empty_kwargs(_deprecated_kwargs)
@@ -1336,7 +1340,11 @@ async def output_validator_deps(ctx: RunContext[str], data: str) -> str:
13361340
return func
13371341

13381342
@deprecated('`result_validator` is deprecated, use `output_validator` instead.')
1339-
def result_validator(self, func: Any, /) -> Any: ...
1343+
def result_validator(self, func: Any, /) -> Any:
1344+
warnings.warn(
1345+
'`result_validator` is deprecated, use `output_validator` instead.', DeprecationWarning, stacklevel=2
1346+
)
1347+
return self.output_validator(func) # type: ignore
13401348

13411349
@overload
13421350
def tool(self, func: ToolFuncContext[AgentDepsT, ToolParams], /) -> ToolFuncContext[AgentDepsT, ToolParams]: ...

pydantic_ai_slim/pydantic_ai/result.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ def coalesce_deprecated_return_content(
551551
warnings.warn(
552552
'`result_tool_return_content` is deprecated, use `output_tool_return_content` instead.',
553553
DeprecationWarning,
554+
stacklevel=3,
554555
)
555556
return result_tool_return_content
556557
return output_tool_return_content

0 commit comments

Comments
 (0)