@@ -896,7 +896,6 @@ def _encode_maxkey(name: bytes, dummy0: Any, dummy1: Any, dummy2: Any) -> bytes:
896896 str : _encode_text ,
897897 tuple : _encode_list ,
898898 type (None ): _encode_none ,
899- decimal .Decimal : _encode_python_decimal ,
900899 uuid .UUID : _encode_uuid ,
901900 Binary : _encode_binary ,
902901 Int64 : _encode_long ,
@@ -920,8 +919,7 @@ def _encode_maxkey(name: bytes, dummy0: Any, dummy1: Any, dummy2: Any) -> bytes:
920919 if hasattr (_typ , "_type_marker" ):
921920 _MARKERS [_typ ._type_marker ] = _ENCODERS [_typ ]
922921
923- # Exclude decimal.Decimal since auto-conversion is explicitly opt-in.
924- _BUILT_IN_TYPES = tuple (t for t in _ENCODERS if t != decimal .Decimal )
922+ _BUILT_IN_TYPES = tuple (t for t in _ENCODERS )
925923
926924
927925def _name_value_to_bson (
@@ -949,6 +947,9 @@ def _name_value_to_bson(
949947 # Give the fallback_encoder a chance
950948 was_integer_overflow = True
951949
950+ if opts .convert_decimal and type (value ) == decimal .Decimal :
951+ return _encode_python_decimal (name , value , check_keys , opts ) # type: ignore
952+
952953 # Second, fall back to trying _type_marker. This has to be done
953954 # before the loop below since users could subclass one of our
954955 # custom types that subclasses a python built-in (e.g. Binary)
@@ -1029,8 +1030,8 @@ def _dict_to_bson(
10291030 return _PACK_INT (len (encoded ) + 5 ) + encoded + b"\x00 "
10301031
10311032
1032- if _USE_C :
1033- _dict_to_bson = _cbson ._dict_to_bson
1033+ # if _USE_C:
1034+ # _dict_to_bson = _cbson._dict_to_bson
10341035
10351036
10361037_CODEC_OPTIONS_TYPE_ERROR = TypeError ("codec_options must be an instance of CodecOptions" )
0 commit comments