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 64
64
class DecimalEncoder (TypeEncoder ):
65
65
"""Converts Python :class:`decimal.Decimal` to BSON :class:`Decimal128`.
66
66
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)
69
70
70
71
.. versionadded:: 4.15"""
71
72
@@ -80,8 +81,9 @@ def transform_python(self, value: Any) -> Decimal128:
80
81
class DecimalDecoder (TypeDecoder ):
81
82
"""Converts BSON :class:`Decimal128` to Python :class:`decimal.Decimal`.
82
83
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)
85
87
86
88
.. versionadded:: 4.15"""
87
89
Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ Changelog
2
2
=========
3
3
Changes in Version 4.15.0 (XXXX/XX/XX)
4
4
--------------------------------------
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
-
8
5
PyMongo 4.15 brings a number of changes including:
9
6
10
7
- Added :class: `bson.decimal128.DecimalEncoder ` and :class: `bson.decimal128.DecimalDecoder `
You can’t perform that action at this time.
0 commit comments