@@ -244,7 +244,7 @@ def _raise_unknown_type(element_type: int, element_name: str) -> NoReturn:
244244
245245
246246def _get_int (
247- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
247+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
248248) -> Tuple [int , int ]:
249249 """Decode a BSON int32 to python int."""
250250 return _UNPACK_INT_FROM (data , position )[0 ], position + 4
@@ -257,7 +257,7 @@ def _get_c_string(data: Any, view: Any, position: int, opts: CodecOptions[Any])
257257
258258
259259def _get_float (
260- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
260+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
261261) -> Tuple [float , int ]:
262262 """Decode a BSON double to python float."""
263263 return _UNPACK_FLOAT_FROM (data , position )[0 ], position + 8
@@ -282,7 +282,7 @@ def _get_object_size(data: Any, position: int, obj_end: int) -> Tuple[int, int]:
282282 try :
283283 obj_size = _UNPACK_INT_FROM (data , position )[0 ]
284284 except struct .error as exc :
285- raise InvalidBSON (str (exc ))
285+ raise InvalidBSON (str (exc )) from None
286286 end = position + obj_size - 1
287287 if data [end ] != 0 :
288288 raise InvalidBSON ("bad eoo" )
@@ -358,7 +358,7 @@ def _get_array(
358358
359359
360360def _get_binary (
361- data : Any , view : Any , position : int , obj_end : int , opts : CodecOptions [Any ], dummy1 : Any
361+ data : Any , _view : Any , position : int , obj_end : int , opts : CodecOptions [Any ], dummy1 : Any
362362) -> Tuple [Union [Binary , uuid .UUID ], int ]:
363363 """Decode a BSON binary to bson.binary.Binary or python UUID."""
364364 length , subtype = _UNPACK_LENGTH_SUBTYPE_FROM (data , position )
@@ -395,15 +395,15 @@ def _get_binary(
395395
396396
397397def _get_oid (
398- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
398+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
399399) -> Tuple [ObjectId , int ]:
400400 """Decode a BSON ObjectId to bson.objectid.ObjectId."""
401401 end = position + 12
402402 return ObjectId (data [position :end ]), end
403403
404404
405405def _get_boolean (
406- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
406+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
407407) -> Tuple [bool , int ]:
408408 """Decode a BSON true/false to python True/False."""
409409 end = position + 1
@@ -416,7 +416,7 @@ def _get_boolean(
416416
417417
418418def _get_date (
419- data : Any , view : Any , position : int , dummy0 : int , opts : CodecOptions [Any ], dummy1 : Any
419+ data : Any , _view : Any , position : int , dummy0 : int , opts : CodecOptions [Any ], dummy1 : Any
420420) -> Tuple [Union [datetime .datetime , DatetimeMS ], int ]:
421421 """Decode a BSON datetime to python datetime.datetime."""
422422 return _millis_to_datetime (_UNPACK_LONG_FROM (data , position )[0 ], opts ), position + 8
@@ -431,7 +431,7 @@ def _get_code(
431431
432432
433433def _get_code_w_scope (
434- data : Any , view : Any , position : int , obj_end : int , opts : CodecOptions [Any ], element_name : str
434+ data : Any , view : Any , position : int , _obj_end : int , opts : CodecOptions [Any ], element_name : str
435435) -> Tuple [Code , int ]:
436436 """Decode a BSON code_w_scope to bson.code.Code."""
437437 code_end = position + _UNPACK_INT_FROM (data , position )[0 ]
@@ -462,22 +462,22 @@ def _get_ref(
462462
463463
464464def _get_timestamp (
465- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
465+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
466466) -> Tuple [Timestamp , int ]:
467467 """Decode a BSON timestamp to bson.timestamp.Timestamp."""
468468 inc , timestamp = _UNPACK_TIMESTAMP_FROM (data , position )
469469 return Timestamp (timestamp , inc ), position + 8
470470
471471
472472def _get_int64 (
473- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
473+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
474474) -> Tuple [Int64 , int ]:
475475 """Decode a BSON int64 to bson.int64.Int64."""
476476 return Int64 (_UNPACK_LONG_FROM (data , position )[0 ]), position + 8
477477
478478
479479def _get_decimal128 (
480- data : Any , view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
480+ data : Any , _view : Any , position : int , dummy0 : Any , dummy1 : Any , dummy2 : Any
481481) -> Tuple [Decimal128 , int ]:
482482 """Decode a BSON decimal128 to bson.decimal128.Decimal128."""
483483 end = position + 16
@@ -496,11 +496,11 @@ def _get_decimal128(
496496 ord (BSONOBJ ): _get_object ,
497497 ord (BSONARR ): _get_array ,
498498 ord (BSONBIN ): _get_binary ,
499- ord (BSONUND ): lambda u , v , w , x , y , z : (None , w ), # Deprecated undefined
499+ ord (BSONUND ): lambda u , v , w , x , y , z : (None , w ), # noqa: ARG005 # Deprecated undefined
500500 ord (BSONOID ): _get_oid ,
501501 ord (BSONBOO ): _get_boolean ,
502502 ord (BSONDAT ): _get_date ,
503- ord (BSONNUL ): lambda u , v , w , x , y , z : (None , w ),
503+ ord (BSONNUL ): lambda u , v , w , x , y , z : (None , w ), # noqa: ARG005
504504 ord (BSONRGX ): _get_regex ,
505505 ord (BSONREF ): _get_ref , # Deprecated DBPointer
506506 ord (BSONCOD ): _get_code ,
@@ -510,16 +510,16 @@ def _get_decimal128(
510510 ord (BSONTIM ): _get_timestamp ,
511511 ord (BSONLON ): _get_int64 ,
512512 ord (BSONDEC ): _get_decimal128 ,
513- ord (BSONMIN ): lambda u , v , w , x , y , z : (MinKey (), w ),
514- ord (BSONMAX ): lambda u , v , w , x , y , z : (MaxKey (), w ),
513+ ord (BSONMIN ): lambda u , v , w , x , y , z : (MinKey (), w ), # noqa: ARG005
514+ ord (BSONMAX ): lambda u , v , w , x , y , z : (MaxKey (), w ), # noqa: ARG005
515515}
516516
517517
518518if _USE_C :
519519
520520 def _element_to_dict (
521521 data : Any ,
522- view : Any ,
522+ view : Any , # noqa: ARG001
523523 position : int ,
524524 obj_end : int ,
525525 opts : CodecOptions [Any ],
@@ -615,11 +615,11 @@ def _bson_to_dict(data: Any, opts: CodecOptions[_DocumentType]) -> _DocumentType
615615 except Exception :
616616 # Change exception type to InvalidBSON but preserve traceback.
617617 _ , exc_value , exc_tb = sys .exc_info ()
618- raise InvalidBSON (str (exc_value )).with_traceback (exc_tb )
618+ raise InvalidBSON (str (exc_value )).with_traceback (exc_tb ) from None
619619
620620
621621if _USE_C :
622- _bson_to_dict = _cbson ._bson_to_dict # noqa: F811
622+ _bson_to_dict = _cbson ._bson_to_dict
623623
624624
625625_PACK_FLOAT = struct .Struct ("<d" ).pack
@@ -653,7 +653,9 @@ def _make_c_string_check(string: Union[str, bytes]) -> bytes:
653653 _utf_8_decode (string , None , True )
654654 return string + b"\x00 "
655655 except UnicodeError :
656- raise InvalidStringData ("strings in documents must be valid UTF-8: %r" % string )
656+ raise InvalidStringData (
657+ "strings in documents must be valid UTF-8: %r" % string
658+ ) from None
657659 else :
658660 if "\x00 " in string :
659661 raise InvalidDocument ("BSON keys / regex patterns must not contain a NUL character" )
@@ -667,7 +669,9 @@ def _make_c_string(string: Union[str, bytes]) -> bytes:
667669 _utf_8_decode (string , None , True )
668670 return string + b"\x00 "
669671 except UnicodeError :
670- raise InvalidStringData ("strings in documents must be valid UTF-8: %r" % string )
672+ raise InvalidStringData (
673+ "strings in documents must be valid UTF-8: %r" % string
674+ ) from None
671675 else :
672676 return _utf_8_encode (string )[0 ] + b"\x00 "
673677
@@ -817,7 +821,7 @@ def _encode_int(name: bytes, value: int, dummy0: Any, dummy1: Any) -> bytes:
817821 try :
818822 return b"\x12 " + name + _PACK_LONG (value )
819823 except struct .error :
820- raise OverflowError ("BSON can only handle up to 8-byte ints" )
824+ raise OverflowError ("BSON can only handle up to 8-byte ints" ) from None
821825
822826
823827def _encode_timestamp (name : bytes , value : Any , dummy0 : Any , dummy1 : Any ) -> bytes :
@@ -830,7 +834,7 @@ def _encode_long(name: bytes, value: Any, dummy0: Any, dummy1: Any) -> bytes:
830834 try :
831835 return b"\x12 " + name + _PACK_LONG (value )
832836 except struct .error :
833- raise OverflowError ("BSON can only handle up to 8-byte ints" )
837+ raise OverflowError ("BSON can only handle up to 8-byte ints" ) from None
834838
835839
836840def _encode_decimal128 (name : bytes , value : Decimal128 , dummy0 : Any , dummy1 : Any ) -> bytes :
@@ -995,14 +999,14 @@ def _dict_to_bson(
995999 if not top_level or key != "_id" :
9961000 elements .append (_element_to_bson (key , value , check_keys , opts ))
9971001 except AttributeError :
998- raise TypeError (f"encoder expected a mapping type but got: { doc !r} " )
1002+ raise TypeError (f"encoder expected a mapping type but got: { doc !r} " ) from None
9991003
10001004 encoded = b"" .join (elements )
10011005 return _PACK_INT (len (encoded ) + 5 ) + encoded + b"\x00 "
10021006
10031007
10041008if _USE_C :
1005- _dict_to_bson = _cbson ._dict_to_bson # noqa: F811
1009+ _dict_to_bson = _cbson ._dict_to_bson
10061010
10071011
10081012_CODEC_OPTIONS_TYPE_ERROR = TypeError ("codec_options must be an instance of CodecOptions" )
@@ -1110,11 +1114,11 @@ def _decode_all(data: _ReadableBuffer, opts: CodecOptions[_DocumentType]) -> lis
11101114 except Exception :
11111115 # Change exception type to InvalidBSON but preserve traceback.
11121116 _ , exc_value , exc_tb = sys .exc_info ()
1113- raise InvalidBSON (str (exc_value )).with_traceback (exc_tb )
1117+ raise InvalidBSON (str (exc_value )).with_traceback (exc_tb ) from None
11141118
11151119
11161120if _USE_C :
1117- _decode_all = _cbson ._decode_all # noqa: F811
1121+ _decode_all = _cbson ._decode_all
11181122
11191123
11201124@overload
@@ -1207,7 +1211,7 @@ def _array_of_documents_to_buffer(view: memoryview) -> bytes:
12071211
12081212
12091213if _USE_C :
1210- _array_of_documents_to_buffer = _cbson ._array_of_documents_to_buffer # noqa: F811
1214+ _array_of_documents_to_buffer = _cbson ._array_of_documents_to_buffer
12111215
12121216
12131217def _convert_raw_document_lists_to_streams (document : Any ) -> None :
0 commit comments