@@ -244,7 +244,7 @@ def _raise_unknown_type(element_type: int, element_name: str) -> NoReturn:
244
244
245
245
246
246
def _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
248
248
) -> Tuple [int , int ]:
249
249
"""Decode a BSON int32 to python int."""
250
250
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])
257
257
258
258
259
259
def _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
261
261
) -> Tuple [float , int ]:
262
262
"""Decode a BSON double to python float."""
263
263
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]:
282
282
try :
283
283
obj_size = _UNPACK_INT_FROM (data , position )[0 ]
284
284
except struct .error as exc :
285
- raise InvalidBSON (str (exc ))
285
+ raise InvalidBSON (str (exc )) from None
286
286
end = position + obj_size - 1
287
287
if data [end ] != 0 :
288
288
raise InvalidBSON ("bad eoo" )
@@ -358,7 +358,7 @@ def _get_array(
358
358
359
359
360
360
def _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
362
362
) -> Tuple [Union [Binary , uuid .UUID ], int ]:
363
363
"""Decode a BSON binary to bson.binary.Binary or python UUID."""
364
364
length , subtype = _UNPACK_LENGTH_SUBTYPE_FROM (data , position )
@@ -395,15 +395,15 @@ def _get_binary(
395
395
396
396
397
397
def _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
399
399
) -> Tuple [ObjectId , int ]:
400
400
"""Decode a BSON ObjectId to bson.objectid.ObjectId."""
401
401
end = position + 12
402
402
return ObjectId (data [position :end ]), end
403
403
404
404
405
405
def _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
407
407
) -> Tuple [bool , int ]:
408
408
"""Decode a BSON true/false to python True/False."""
409
409
end = position + 1
@@ -416,7 +416,7 @@ def _get_boolean(
416
416
417
417
418
418
def _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
420
420
) -> Tuple [Union [datetime .datetime , DatetimeMS ], int ]:
421
421
"""Decode a BSON datetime to python datetime.datetime."""
422
422
return _millis_to_datetime (_UNPACK_LONG_FROM (data , position )[0 ], opts ), position + 8
@@ -431,7 +431,7 @@ def _get_code(
431
431
432
432
433
433
def _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
435
435
) -> Tuple [Code , int ]:
436
436
"""Decode a BSON code_w_scope to bson.code.Code."""
437
437
code_end = position + _UNPACK_INT_FROM (data , position )[0 ]
@@ -462,22 +462,22 @@ def _get_ref(
462
462
463
463
464
464
def _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
466
466
) -> Tuple [Timestamp , int ]:
467
467
"""Decode a BSON timestamp to bson.timestamp.Timestamp."""
468
468
inc , timestamp = _UNPACK_TIMESTAMP_FROM (data , position )
469
469
return Timestamp (timestamp , inc ), position + 8
470
470
471
471
472
472
def _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
474
474
) -> Tuple [Int64 , int ]:
475
475
"""Decode a BSON int64 to bson.int64.Int64."""
476
476
return Int64 (_UNPACK_LONG_FROM (data , position )[0 ]), position + 8
477
477
478
478
479
479
def _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
481
481
) -> Tuple [Decimal128 , int ]:
482
482
"""Decode a BSON decimal128 to bson.decimal128.Decimal128."""
483
483
end = position + 16
@@ -496,11 +496,11 @@ def _get_decimal128(
496
496
ord (BSONOBJ ): _get_object ,
497
497
ord (BSONARR ): _get_array ,
498
498
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
500
500
ord (BSONOID ): _get_oid ,
501
501
ord (BSONBOO ): _get_boolean ,
502
502
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
504
504
ord (BSONRGX ): _get_regex ,
505
505
ord (BSONREF ): _get_ref , # Deprecated DBPointer
506
506
ord (BSONCOD ): _get_code ,
@@ -510,16 +510,16 @@ def _get_decimal128(
510
510
ord (BSONTIM ): _get_timestamp ,
511
511
ord (BSONLON ): _get_int64 ,
512
512
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
515
515
}
516
516
517
517
518
518
if _USE_C :
519
519
520
520
def _element_to_dict (
521
521
data : Any ,
522
- view : Any ,
522
+ view : Any , # noqa: ARG001
523
523
position : int ,
524
524
obj_end : int ,
525
525
opts : CodecOptions [Any ],
@@ -615,11 +615,11 @@ def _bson_to_dict(data: Any, opts: CodecOptions[_DocumentType]) -> _DocumentType
615
615
except Exception :
616
616
# Change exception type to InvalidBSON but preserve traceback.
617
617
_ , 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
619
619
620
620
621
621
if _USE_C :
622
- _bson_to_dict = _cbson ._bson_to_dict # noqa: F811
622
+ _bson_to_dict = _cbson ._bson_to_dict
623
623
624
624
625
625
_PACK_FLOAT = struct .Struct ("<d" ).pack
@@ -653,7 +653,9 @@ def _make_c_string_check(string: Union[str, bytes]) -> bytes:
653
653
_utf_8_decode (string , None , True )
654
654
return string + b"\x00 "
655
655
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
657
659
else :
658
660
if "\x00 " in string :
659
661
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:
667
669
_utf_8_decode (string , None , True )
668
670
return string + b"\x00 "
669
671
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
671
675
else :
672
676
return _utf_8_encode (string )[0 ] + b"\x00 "
673
677
@@ -817,7 +821,7 @@ def _encode_int(name: bytes, value: int, dummy0: Any, dummy1: Any) -> bytes:
817
821
try :
818
822
return b"\x12 " + name + _PACK_LONG (value )
819
823
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
821
825
822
826
823
827
def _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:
830
834
try :
831
835
return b"\x12 " + name + _PACK_LONG (value )
832
836
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
834
838
835
839
836
840
def _encode_decimal128 (name : bytes , value : Decimal128 , dummy0 : Any , dummy1 : Any ) -> bytes :
@@ -995,14 +999,14 @@ def _dict_to_bson(
995
999
if not top_level or key != "_id" :
996
1000
elements .append (_element_to_bson (key , value , check_keys , opts ))
997
1001
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
999
1003
1000
1004
encoded = b"" .join (elements )
1001
1005
return _PACK_INT (len (encoded ) + 5 ) + encoded + b"\x00 "
1002
1006
1003
1007
1004
1008
if _USE_C :
1005
- _dict_to_bson = _cbson ._dict_to_bson # noqa: F811
1009
+ _dict_to_bson = _cbson ._dict_to_bson
1006
1010
1007
1011
1008
1012
_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
1110
1114
except Exception :
1111
1115
# Change exception type to InvalidBSON but preserve traceback.
1112
1116
_ , 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
1114
1118
1115
1119
1116
1120
if _USE_C :
1117
- _decode_all = _cbson ._decode_all # noqa: F811
1121
+ _decode_all = _cbson ._decode_all
1118
1122
1119
1123
1120
1124
@overload
@@ -1207,7 +1211,7 @@ def _array_of_documents_to_buffer(view: memoryview) -> bytes:
1207
1211
1208
1212
1209
1213
if _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
1211
1215
1212
1216
1213
1217
def _convert_raw_document_lists_to_streams (document : Any ) -> None :
0 commit comments