@@ -1106,9 +1106,21 @@ def _decode_all(
11061106 _decode_all = _cbson ._decode_all # noqa: F811
11071107
11081108
1109+ @overload
1110+ def decode_all (data : "_ReadableBuffer" , codec_options : None = None ) -> "List[Dict[str, Any]]" :
1111+ ...
1112+
1113+
1114+ @overload
11091115def decode_all (
1110- data : "_ReadableBuffer" , codec_options : "Optional[ CodecOptions[_DocumentType]]" = None
1116+ data : "_ReadableBuffer" , codec_options : "CodecOptions[_DocumentType]"
11111117) -> "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]]" :
11121124 """Decode BSON data to multiple documents.
11131125
11141126 `data` must be a bytes-like object implementing the buffer protocol that
@@ -1131,11 +1143,13 @@ def decode_all(
11311143 Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with
11321144 `codec_options`.
11331145 """
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 ):
11361150 raise _CODEC_OPTIONS_TYPE_ERROR
11371151
1138- return _decode_all (data , opts ) # type:ignore[arg-type]
1152+ return _decode_all (data , codec_options )
11391153
11401154
11411155def _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) -
12421256 ]
12431257
12441258
1259+ @overload
1260+ def decode_iter (data : bytes , codec_options : None = None ) -> "Iterator[Dict[str, Any]]" :
1261+ ...
1262+
1263+
1264+ @overload
12451265def decode_iter (
1246- data : bytes , codec_options : "Optional[ CodecOptions[_DocumentType]]" = None
1266+ data : bytes , codec_options : "CodecOptions[_DocumentType]"
12471267) -> "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]]" :
12481274 """Decode BSON data to multiple documents as a generator.
12491275
12501276 Works similarly to the decode_all function, but yields one document at a
@@ -1278,9 +1304,23 @@ def decode_iter(
12781304 yield _bson_to_dict (elements , opts )
12791305
12801306
1307+ @overload
12811308def 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]"
12831317) -> "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]]" :
12841324 """Decode bson data from a file to multiple documents as a generator.
12851325
12861326 Works similarly to the decode_all function, but reads from the file object
0 commit comments