@@ -1106,9 +1106,21 @@ def _decode_all(
1106
1106
_decode_all = _cbson ._decode_all # noqa: F811
1107
1107
1108
1108
1109
+ @overload
1110
+ def decode_all (data : "_ReadableBuffer" , codec_options : None = None ) -> "List[Dict[str, Any]]" :
1111
+ ...
1112
+
1113
+
1114
+ @overload
1109
1115
def decode_all (
1110
- data : "_ReadableBuffer" , codec_options : "Optional[ CodecOptions[_DocumentType]]" = None
1116
+ data : "_ReadableBuffer" , codec_options : "CodecOptions[_DocumentType]"
1111
1117
) -> "List[_DocumentType]" :
1118
+ ...
1119
+
1120
+
1121
+ def decode_all (
1122
+ data : "_ReadableBuffer" , codec_options : "Optional[CodecOptions[_DocumentType]]" = None
1123
+ ) -> "Union[List[Dict[str, Any]], List[_DocumentType]]" :
1112
1124
"""Decode BSON data to multiple documents.
1113
1125
1114
1126
`data` must be a bytes-like object implementing the buffer protocol that
@@ -1131,11 +1143,13 @@ def decode_all(
1131
1143
Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with
1132
1144
`codec_options`.
1133
1145
"""
1134
- opts = codec_options or DEFAULT_CODEC_OPTIONS
1135
- if not isinstance (opts , CodecOptions ):
1146
+ if codec_options is None :
1147
+ return _decode_all (data , DEFAULT_CODEC_OPTIONS )
1148
+
1149
+ if not isinstance (codec_options , CodecOptions ):
1136
1150
raise _CODEC_OPTIONS_TYPE_ERROR
1137
1151
1138
- return _decode_all (data , opts ) # type:ignore[arg-type]
1152
+ return _decode_all (data , codec_options )
1139
1153
1140
1154
1141
1155
def _decode_selective (rawdoc : Any , fields : Any , codec_options : Any ) -> Mapping [Any , Any ]:
@@ -1242,9 +1256,21 @@ def _decode_all_selective(data: Any, codec_options: CodecOptions, fields: Any) -
1242
1256
]
1243
1257
1244
1258
1259
+ @overload
1260
+ def decode_iter (data : bytes , codec_options : None = None ) -> "Iterator[Dict[str, Any]]" :
1261
+ ...
1262
+
1263
+
1264
+ @overload
1245
1265
def decode_iter (
1246
- data : bytes , codec_options : "Optional[ CodecOptions[_DocumentType]]" = None
1266
+ data : bytes , codec_options : "CodecOptions[_DocumentType]"
1247
1267
) -> "Iterator[_DocumentType]" :
1268
+ ...
1269
+
1270
+
1271
+ def decode_iter (
1272
+ data : bytes , codec_options : "Optional[CodecOptions[_DocumentType]]" = None
1273
+ ) -> "Union[Iterator[Dict[str, Any]], Iterator[_DocumentType]]" :
1248
1274
"""Decode BSON data to multiple documents as a generator.
1249
1275
1250
1276
Works similarly to the decode_all function, but yields one document at a
@@ -1278,9 +1304,23 @@ def decode_iter(
1278
1304
yield _bson_to_dict (elements , opts )
1279
1305
1280
1306
1307
+ @overload
1281
1308
def decode_file_iter (
1282
- file_obj : Union [BinaryIO , IO ], codec_options : "Optional[CodecOptions[_DocumentType]]" = None
1309
+ file_obj : Union [BinaryIO , IO ], codec_options : None = None
1310
+ ) -> "Iterator[Dict[str, Any]]" :
1311
+ ...
1312
+
1313
+
1314
+ @overload
1315
+ def decode_file_iter (
1316
+ file_obj : Union [BinaryIO , IO ], codec_options : "CodecOptions[_DocumentType]"
1283
1317
) -> "Iterator[_DocumentType]" :
1318
+ ...
1319
+
1320
+
1321
+ def decode_file_iter (
1322
+ file_obj : Union [BinaryIO , IO ], codec_options : "Optional[CodecOptions[_DocumentType]]" = None
1323
+ ) -> "Union[Iterator[Dict[str, Any]], Iterator[_DocumentType]]" :
1284
1324
"""Decode bson data from a file to multiple documents as a generator.
1285
1325
1286
1326
Works similarly to the decode_all function, but reads from the file object
0 commit comments