Skip to content

Commit ff327b3

Browse files
PYTHON-2252 Add examples and documentation for new UUID behavior (#467)
1 parent de1e293 commit ff327b3

File tree

5 files changed

+531
-4
lines changed

5 files changed

+531
-4
lines changed

bson/binary.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class UuidRepresentation:
6969
code. When decoding a BSON binary field with a UUID subtype, a
7070
:class:`~bson.binary.Binary` instance will be returned instead of a
7171
:class:`uuid.UUID` instance.
72+
73+
See :ref:`unspecified-representation-details` for details.
7274
7375
.. versionadded:: 3.11
7476
"""
@@ -79,6 +81,8 @@ class UuidRepresentation:
7981
:class:`uuid.UUID` instances will automatically be encoded to
8082
and decoded from BSON binary, using RFC-4122 byte order with
8183
binary subtype :data:`UUID_SUBTYPE`.
84+
85+
See :ref:`standard-representation-details` for details.
8286
8387
.. versionadded:: 3.11
8488
"""
@@ -89,6 +93,8 @@ class UuidRepresentation:
8993
:class:`uuid.UUID` instances will automatically be encoded to
9094
and decoded from BSON binary, using RFC-4122 byte order with
9195
binary subtype :data:`OLD_UUID_SUBTYPE`.
96+
97+
See :ref:`python-legacy-representation-details` for details.
9298
9399
.. versionadded:: 3.11
94100
"""
@@ -99,6 +105,8 @@ class UuidRepresentation:
99105
:class:`uuid.UUID` instances will automatically be encoded to
100106
and decoded from BSON binary subtype :data:`OLD_UUID_SUBTYPE`,
101107
using the Java driver's legacy byte order.
108+
109+
See :ref:`java-legacy-representation-details` for details.
102110
103111
.. versionadded:: 3.11
104112
"""
@@ -109,6 +117,8 @@ class UuidRepresentation:
109117
:class:`uuid.UUID` instances will automatically be encoded to
110118
and decoded from BSON binary subtype :data:`OLD_UUID_SUBTYPE`,
111119
using the C# driver's legacy byte order.
120+
121+
See :ref:`csharp-legacy-representation-details` for details.
112122
113123
.. versionadded:: 3.11
114124
"""
@@ -220,6 +230,7 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
220230
- `uuid_representation`: A member of
221231
:class:`~bson.binary.UuidRepresentation`. Default:
222232
:const:`~bson.binary.UuidRepresentation.STANDARD`.
233+
See :ref:`handling-uuid-data-example` for details.
223234
224235
.. versionadded:: 3.11
225236
"""
@@ -236,7 +247,8 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
236247
"UuidRepresentation.UNSPECIFIED. UUIDs can be manually "
237248
"converted to bson.Binary instances using "
238249
"bson.Binary.from_uuid() or a different UuidRepresentation "
239-
"can be configured.")
250+
"can be configured. See the documentation for "
251+
"UuidRepresentation for more information.")
240252

241253
subtype = OLD_UUID_SUBTYPE
242254
if uuid_representation == UuidRepresentation.PYTHON_LEGACY:
@@ -266,6 +278,7 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
266278
- `uuid_representation`: A member of
267279
:class:`~bson.binary.UuidRepresentation`. Default:
268280
:const:`~bson.binary.UuidRepresentation.STANDARD`.
281+
See :ref:`handling-uuid-data-example` for details.
269282
270283
.. versionadded:: 3.11
271284
"""

bson/codec_options.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ class CodecOptions(_options_base):
218218
naive. Defaults to ``False``.
219219
- `uuid_representation`: The BSON representation to use when encoding
220220
and decoding instances of :class:`~uuid.UUID`. Defaults to
221-
:data:`~bson.binary.PYTHON_LEGACY`.
221+
:data:`~bson.binary.UuidRepresentation.PYTHON_LEGACY`. New
222+
applications should consider setting this to
223+
:data:`~bson.binary.UuidRepresentation.STANDARD` for cross language
224+
compatibility. See :ref:`handling-uuid-data-example` for details.
222225
- `unicode_decode_error_handler`: The error handler to apply when
223226
a Unicode-related error occurs during BSON decoding that would
224227
otherwise raise :exc:`UnicodeDecodeError`. Valid options include

doc/examples/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ MongoDB, you can start it like so:
3232
tailable
3333
tls
3434
encryption
35+
uuid

0 commit comments

Comments
 (0)