Skip to content

Commit f27a993

Browse files
Doc: Clarify UUID bytes attributes
1 parent acefff9 commit f27a993

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

Doc/library/uuid.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ which relays any information about the UUID's safety, using this enumeration:
4444

4545
.. class:: UUID(hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None, *, is_safe=SafeUUID.unknown)
4646

47-
Create a UUID from either a string of 32 hexadecimal digits, a string of 16
48-
bytes in big-endian order as the *bytes* argument, a string of 16 bytes in
49-
little-endian order as the *bytes_le* argument, a tuple of six integers
47+
Create a UUID from either a string of 32 hexadecimal digits, a 16-byte
48+
:class:`bytes` object in big-endian order as the *bytes* argument, a
49+
16-byte :class:`bytes` object in little-endian order as the *bytes_le*
50+
argument, a tuple of six integers
5051
(32-bit *time_low*, 16-bit *time_mid*, 16-bit *time_hi_version*,
5152
8-bit *clock_seq_hi_variant*, 8-bit *clock_seq_low*, 48-bit *node*) as the
5253
*fields* argument, or a single 128-bit integer as the *int* argument.
@@ -80,14 +81,14 @@ which relays any information about the UUID's safety, using this enumeration:
8081

8182
.. attribute:: UUID.bytes
8283

83-
The UUID as a 16-byte string (containing the six integer fields in big-endian
84-
byte order).
84+
The UUID as a 16-byte :class:`bytes` object (containing the six integer
85+
fields in big-endian byte order).
8586

8687

8788
.. attribute:: UUID.bytes_le
8889

89-
The UUID as a 16-byte string (with *time_low*, *time_mid*, and *time_hi_version*
90-
in little-endian byte order).
90+
The UUID as a 16-byte :class:`bytes` object (with *time_low*, *time_mid*,
91+
and *time_hi_version* in little-endian byte order).
9192

9293

9394
.. attribute:: UUID.fields
@@ -435,7 +436,7 @@ Here are some examples of typical usage of the :mod:`!uuid` module::
435436
>>> x.bytes
436437
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
437438

438-
>>> # make a UUID from a 16-byte string
439+
>>> # make a UUID from a 16-byte bytes object
439440
>>> uuid.UUID(bytes=x.bytes)
440441
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
441442

Lib/uuid.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
>>> x.bytes
4444
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
4545
46-
# make a UUID from a 16-byte string
46+
# make a UUID from a 16-byte bytes object
4747
>>> uuid.UUID(bytes=x.bytes)
4848
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
4949
@@ -118,19 +118,19 @@ class UUID:
118118
'12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
119119
five possible forms: a similar string of hexadecimal digits, or a tuple
120120
of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
121-
48-bit values respectively) as an argument named 'fields', or a string
122-
of 16 bytes (with all the integer fields in big-endian order) as an
123-
argument named 'bytes', or a string of 16 bytes (with the first three
124-
fields in little-endian order) as an argument named 'bytes_le', or a
125-
single 128-bit integer as an argument named 'int'.
121+
48-bit values respectively) as an argument named 'fields', or a 16-byte
122+
bytes object (with all the integer fields in big-endian order) as an
123+
argument named 'bytes', or a 16-byte bytes object (with the first three
124+
fields in little-endian order) as an argument named 'bytes_le', or a single
125+
128-bit integer as an argument named 'int'.
126126
127127
UUIDs have these read-only attributes:
128128
129-
bytes the UUID as a 16-byte string (containing the six
129+
bytes the UUID as a 16-byte bytes object (containing the six
130130
integer fields in big-endian byte order)
131131
132-
bytes_le the UUID as a 16-byte string (with time_low, time_mid,
133-
and time_hi_version in little-endian byte order)
132+
bytes_le the UUID as a 16-byte bytes object (with time_low,
133+
time_mid, and time_hi_version in little-endian byte order)
134134
135135
fields a tuple of the six integer fields of the UUID,
136136
which are also available as six individual attributes
@@ -179,7 +179,7 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
179179
int=None, version=None,
180180
*, is_safe=SafeUUID.unknown):
181181
r"""Create a UUID from either a string of 32 hexadecimal digits,
182-
a string of 16 bytes as the 'bytes' argument, a string of 16 bytes
182+
a 16-byte bytes object as the 'bytes' argument, a 16-byte bytes object
183183
in little-endian order as the 'bytes_le' argument, a tuple of six
184184
integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
185185
8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as
@@ -191,9 +191,9 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
191191
UUID('{12345678-1234-5678-1234-567812345678}')
192192
UUID('12345678123456781234567812345678')
193193
UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
194-
UUID(bytes='\x12\x34\x56\x78'*4)
195-
UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
196-
'\x12\x34\x56\x78\x12\x34\x56\x78')
194+
UUID(bytes=b'\x12\x34\x56\x78'*4)
195+
UUID(bytes_le=b'\x78\x56\x34\x12\x34\x12\x78\x56' +
196+
b'\x12\x34\x56\x78\x12\x34\x56\x78')
197197
UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
198198
UUID(int=0x12345678123456781234567812345678)
199199

0 commit comments

Comments
 (0)