13
13
from dirty_equals import IsListOrTuple
14
14
from inline_snapshot import snapshot
15
15
from pydantic import AnyUrl , BaseModel , Discriminator , Field , Tag
16
- from typing_extensions import TypedDict
16
+ from typing_extensions import NotRequired , TypedDict
17
17
18
18
from pydantic_ai import Agent , ModelHTTPError , ModelRetry , UnexpectedModelBehavior
19
19
from pydantic_ai .messages import (
@@ -1082,7 +1082,37 @@ class MyDefaultRecursiveDc:
1082
1082
field : MyDefaultRecursiveDc | None = None
1083
1083
1084
1084
1085
- class MyModel (BaseModel , extra = 'allow' ):
1085
+ class MyModel (BaseModel ):
1086
+ foo : str
1087
+
1088
+
1089
+ class MyDc (BaseModel ):
1090
+ foo : str
1091
+
1092
+
1093
+ class MyOptionalDc (BaseModel ):
1094
+ foo : str | None
1095
+ bar : str
1096
+
1097
+
1098
+ class MyExtrasDc (BaseModel , extra = 'allow' ):
1099
+ foo : str
1100
+
1101
+
1102
+ class MyNormalTypedDict (TypedDict ):
1103
+ foo : str
1104
+
1105
+
1106
+ class MyOptionalTypedDict (TypedDict ):
1107
+ foo : NotRequired [str ]
1108
+ bar : str
1109
+
1110
+
1111
+ class MyPartialTypedDict (TypedDict , total = False ):
1112
+ foo : str
1113
+
1114
+
1115
+ class MyExtrasModel (BaseModel , extra = 'allow' ):
1086
1116
pass
1087
1117
1088
1118
@@ -1106,14 +1136,46 @@ def tool_with_recursion(x: MyRecursiveDc, y: MyDefaultRecursiveDc):
1106
1136
return f'{ x } { y } ' # pragma: no cover
1107
1137
1108
1138
1109
- def tool_with_additional_properties (x : MyModel ) -> str :
1139
+ def tool_with_model (x : MyModel ) -> str :
1140
+ return f'{ x } ' # pragma: no cover
1141
+
1142
+
1143
+ def tool_with_dataclass (x : MyDc ) -> str :
1144
+ return f'{ x } ' # pragma: no cover
1145
+
1146
+
1147
+ def tool_with_optional_dataclass (x : MyOptionalDc ) -> str :
1148
+ return f'{ x } ' # pragma: no cover
1149
+
1150
+
1151
+ def tool_with_dataclass_with_extras (x : MyExtrasDc ) -> str :
1152
+ return f'{ x } ' # pragma: no cover
1153
+
1154
+
1155
+ def tool_with_typed_dict (x : MyNormalTypedDict ) -> str :
1156
+ return f'{ x } ' # pragma: no cover
1157
+
1158
+
1159
+ def tool_with_optional_typed_dict (x : MyOptionalTypedDict ) -> str :
1160
+ return f'{ x } ' # pragma: no cover
1161
+
1162
+
1163
+ def tool_with_partial_typed_dict (x : MyPartialTypedDict ) -> str :
1164
+ return f'{ x } ' # pragma: no cover
1165
+
1166
+
1167
+ def tool_with_model_with_extras (x : MyExtrasModel ) -> str :
1110
1168
return f'{ x } ' # pragma: no cover
1111
1169
1112
1170
1113
1171
def tool_with_kwargs (x : int , ** kwargs : Any ) -> str :
1114
1172
return f'{ x } { kwargs } ' # pragma: no cover
1115
1173
1116
1174
1175
+ def tool_with_typed_kwargs (x : int , ** kwargs : int ) -> str :
1176
+ return f'{ x } { kwargs } ' # pragma: no cover
1177
+
1178
+
1117
1179
def tool_with_union (x : int | MyDefaultDc ) -> str :
1118
1180
return f'{ x } ' # pragma: no cover
1119
1181
@@ -1216,6 +1278,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1216
1278
}
1217
1279
},
1218
1280
'type' : 'object' ,
1281
+ 'additionalProperties' : False ,
1219
1282
},
1220
1283
'MyEnum' : {'enum' : ['a' , 'b' ], 'type' : 'string' },
1221
1284
'MyRecursiveDc' : {
@@ -1225,6 +1288,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1225
1288
},
1226
1289
'required' : ['field' , 'my_enum' ],
1227
1290
'type' : 'object' ,
1291
+ 'additionalProperties' : False ,
1228
1292
},
1229
1293
},
1230
1294
'additionalProperties' : False ,
@@ -1275,7 +1339,97 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1275
1339
snapshot (True ),
1276
1340
),
1277
1341
(
1278
- tool_with_additional_properties ,
1342
+ tool_with_model ,
1343
+ None ,
1344
+ snapshot (
1345
+ {
1346
+ 'additionalProperties' : False ,
1347
+ 'properties' : {'foo' : {'type' : 'string' }},
1348
+ 'required' : ['foo' ],
1349
+ 'type' : 'object' ,
1350
+ }
1351
+ ),
1352
+ snapshot (True ),
1353
+ ),
1354
+ (
1355
+ tool_with_dataclass ,
1356
+ None ,
1357
+ snapshot (
1358
+ {
1359
+ 'additionalProperties' : False ,
1360
+ 'properties' : {'foo' : {'type' : 'string' }},
1361
+ 'required' : ['foo' ],
1362
+ 'type' : 'object' ,
1363
+ }
1364
+ ),
1365
+ snapshot (True ),
1366
+ ),
1367
+ (
1368
+ tool_with_optional_dataclass ,
1369
+ None ,
1370
+ snapshot (
1371
+ {
1372
+ 'additionalProperties' : False ,
1373
+ 'properties' : {'foo' : {'anyOf' : [{'type' : 'string' }, {'type' : 'null' }]}, 'bar' : {'type' : 'string' }},
1374
+ 'required' : ['foo' , 'bar' ],
1375
+ 'type' : 'object' ,
1376
+ }
1377
+ ),
1378
+ snapshot (True ),
1379
+ ),
1380
+ (
1381
+ tool_with_dataclass_with_extras ,
1382
+ None ,
1383
+ snapshot (
1384
+ {
1385
+ 'additionalProperties' : True ,
1386
+ 'properties' : {'foo' : {'type' : 'string' }},
1387
+ 'required' : ['foo' ],
1388
+ 'type' : 'object' ,
1389
+ }
1390
+ ),
1391
+ snapshot (None ),
1392
+ ),
1393
+ (
1394
+ tool_with_typed_dict ,
1395
+ None ,
1396
+ snapshot (
1397
+ {
1398
+ 'additionalProperties' : False ,
1399
+ 'properties' : {'foo' : {'type' : 'string' }},
1400
+ 'required' : ['foo' ],
1401
+ 'type' : 'object' ,
1402
+ }
1403
+ ),
1404
+ snapshot (True ),
1405
+ ),
1406
+ (
1407
+ tool_with_optional_typed_dict ,
1408
+ None ,
1409
+ snapshot (
1410
+ {
1411
+ 'additionalProperties' : False ,
1412
+ 'properties' : {'foo' : {'type' : 'string' }, 'bar' : {'type' : 'string' }},
1413
+ 'required' : ['bar' ],
1414
+ 'type' : 'object' ,
1415
+ }
1416
+ ),
1417
+ snapshot (None ),
1418
+ ),
1419
+ (
1420
+ tool_with_partial_typed_dict ,
1421
+ None ,
1422
+ snapshot (
1423
+ {
1424
+ 'additionalProperties' : False ,
1425
+ 'properties' : {'foo' : {'type' : 'string' }},
1426
+ 'type' : 'object' ,
1427
+ }
1428
+ ),
1429
+ snapshot (None ),
1430
+ ),
1431
+ (
1432
+ tool_with_model_with_extras ,
1279
1433
None ,
1280
1434
snapshot (
1281
1435
{
@@ -1287,7 +1441,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1287
1441
snapshot (None ),
1288
1442
),
1289
1443
(
1290
- tool_with_additional_properties ,
1444
+ tool_with_model_with_extras ,
1291
1445
True ,
1292
1446
snapshot (
1293
1447
{
@@ -1304,6 +1458,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1304
1458
None ,
1305
1459
snapshot (
1306
1460
{
1461
+ 'additionalProperties' : True ,
1307
1462
'properties' : {'x' : {'type' : 'integer' }},
1308
1463
'required' : ['x' ],
1309
1464
'type' : 'object' ,
@@ -1324,6 +1479,19 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1324
1479
),
1325
1480
snapshot (True ),
1326
1481
),
1482
+ (
1483
+ tool_with_typed_kwargs ,
1484
+ None ,
1485
+ snapshot (
1486
+ {
1487
+ 'additionalProperties' : {'type' : 'integer' },
1488
+ 'properties' : {'x' : {'type' : 'integer' }},
1489
+ 'required' : ['x' ],
1490
+ 'type' : 'object' ,
1491
+ }
1492
+ ),
1493
+ snapshot (None ),
1494
+ ),
1327
1495
(
1328
1496
tool_with_union ,
1329
1497
None ,
@@ -1333,6 +1501,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1333
1501
'MyDefaultDc' : {
1334
1502
'properties' : {'x' : {'default' : 1 , 'type' : 'integer' }},
1335
1503
'type' : 'object' ,
1504
+ 'additionalProperties' : False ,
1336
1505
}
1337
1506
},
1338
1507
'additionalProperties' : False ,
@@ -1373,6 +1542,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1373
1542
'MyDefaultDc' : {
1374
1543
'properties' : {'x' : {'default' : 1 , 'type' : 'integer' }},
1375
1544
'type' : 'object' ,
1545
+ 'additionalProperties' : False ,
1376
1546
}
1377
1547
},
1378
1548
'additionalProperties' : False ,
@@ -1413,6 +1583,7 @@ def tool_with_tuples(x: tuple[int], y: tuple[str] = ('abc',)) -> str:
1413
1583
'MyDefaultDc' : {
1414
1584
'properties' : {'x' : {'default' : 1 , 'type' : 'integer' }},
1415
1585
'type' : 'object' ,
1586
+ 'additionalProperties' : False ,
1416
1587
}
1417
1588
},
1418
1589
'additionalProperties' : False ,
0 commit comments