Skip to content

Commit 6b5e4a8

Browse files
committed
Issue python#26267: Improve uuid.UUID documentation
* Document how comparison of UUID objects work * Document str(uuid) returns the braceless standard form * Add a test for comparison of a UUID object with a non-UUID object Patch by Ammar Askar.
1 parent 195319e commit 6b5e4a8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Doc/library/uuid.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ random UUID.
4545
variant and version number set according to RFC 4122, overriding bits in the
4646
given *hex*, *bytes*, *bytes_le*, *fields*, or *int*.
4747

48+
Comparison of UUID objects are made by way of comparing their
49+
:attr:`UUID.int` attributes. Comparison with a non-UUID object
50+
raises a :exc:`TypeError`.
51+
52+
``str(uuid)`` returns a string in the form
53+
``12345678-1234-5678-1234-567812345678`` where the 32 hexadecimal digits
54+
represent the UUID.
4855

4956
:class:`UUID` instances have these read-only attributes:
5057

Lib/test/test_uuid.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ def test_exceptions(self):
292292
badtype(lambda: setattr(u, 'clock_seq_low', 0))
293293
badtype(lambda: setattr(u, 'node', 0))
294294

295+
# Comparison with a non-UUID object
296+
badtype(lambda: u < object())
297+
badtype(lambda: u > object())
298+
295299
def test_getnode(self):
296300
node1 = uuid.getnode()
297301
self.assertTrue(0 < node1 < (1 << 48), '%012x' % node1)

0 commit comments

Comments
 (0)