File tree Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change 6464class DecimalEncoder (TypeEncoder ):
6565 """Converts Python :class:`decimal.Decimal` to BSON :class:`Decimal128`.
6666
67- .. warning:: When converting BSON data types to and from built-in data types,
68- the possibility of data loss is always present due to mismatches in underlying implementations.
67+ For example::
68+ opts = CodecOptions(type_registry=TypeRegistry([DecimalEncoder()]))
69+ bson.encode({"d": decimal.Decimal('1.0')}, codec_options=opts)
6970
7071 .. versionadded:: 4.15"""
7172
@@ -80,8 +81,9 @@ def transform_python(self, value: Any) -> Decimal128:
8081class DecimalDecoder (TypeDecoder ):
8182 """Converts BSON :class:`Decimal128` to Python :class:`decimal.Decimal`.
8283
83- .. warning:: When converting BSON data types to and from built-in data types,
84- the possibility of data loss is always present due to mismatches in underlying implementations.
84+ For example::
85+ opts = CodecOptions(type_registry=TypeRegistry([DecimalDecoder()]))
86+ bson.decode(b'\x18 \x00 \x00 \x00 \x13 d\x00 \n \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 >0\x00 ', codec_options=opts)
8587
8688 .. versionadded:: 4.15"""
8789
Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ Changelog
22=========
33Changes in Version 4.15.0 (XXXX/XX/XX)
44--------------------------------------
5- .. warning :: When converting BSON data types to and from built-in data types, the possibility of data loss is always present
6- due to mismatches in underlying implementations.
7-
85PyMongo 4.15 brings a number of changes including:
96
107- Added :class: `bson.decimal128.DecimalEncoder ` and :class: `bson.decimal128.DecimalDecoder `
You can’t perform that action at this time.
0 commit comments