1
1
import asyncio
2
2
import json
3
- from typing import Any
3
+ from typing import Any , Optional
4
4
5
5
import pytest
6
6
@@ -145,7 +145,7 @@ async def test_no_error_on_invalid_json_async():
145
145
146
146
147
147
@function_tool (strict_mode = False )
148
- def optional_param_function (a : int , b : int | None = None ) -> str :
148
+ def optional_param_function (a : int , b : Optional [ int ] = None ) -> str :
149
149
if b is None :
150
150
return f"{ a } _no_b"
151
151
return f"{ a } _{ b } "
@@ -165,17 +165,22 @@ async def test_optional_param_function():
165
165
166
166
167
167
@function_tool (strict_mode = False )
168
- def multiple_optional_params_function (x : int = 42 , y : str = "hello" , z : int | None = None ) -> str :
168
+ def multiple_optional_params_function (
169
+ x : int = 42 ,
170
+ y : str = "hello" ,
171
+ z : Optional [int ] = None ,
172
+ ) -> str :
169
173
if z is None :
170
174
return f"{ x } _{ y } _no_z"
171
175
return f"{ x } _{ y } _{ z } "
172
176
173
177
178
+
174
179
@pytest .mark .asyncio
175
180
async def test_multiple_optional_params_function ():
176
181
tool = multiple_optional_params_function
177
182
178
- input_data = {}
183
+ input_data : dict [ str , Any ] = {}
179
184
output = await tool .on_invoke_tool (ctx_wrapper (), json .dumps (input_data ))
180
185
assert output == "42_hello_no_z"
181
186
@@ -185,4 +190,4 @@ async def test_multiple_optional_params_function():
185
190
186
191
input_data = {"x" : 10 , "y" : "world" , "z" : 99 }
187
192
output = await tool .on_invoke_tool (ctx_wrapper (), json .dumps (input_data ))
188
- assert output == "10_world_99"
193
+ assert output == "10_world_99"
0 commit comments