[Python-checkins] cpython (3.5): Issue #26267: Improve uuid.UUID documentation
berker.peksag
python-checkins at python.org
Sat Dec 31 12:06:56 EST 2016
https://hg.python.org/cpython/rev/1a25c639f81e
changeset: 105906:1a25c639f81e
branch: 3.5
parent: 105900:1e1e24629218
user: Berker Peksag <berker.peksag at gmail.com>
date: Sat Dec 31 20:08:16 2016 +0300
summary:
Issue #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.
files:
Doc/library/uuid.rst | 7 +++++++
Lib/test/test_uuid.py | 4 ++++
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/Doc/library/uuid.rst b/Doc/library/uuid.rst
--- a/Doc/library/uuid.rst
+++ b/Doc/library/uuid.rst
@@ -45,6 +45,13 @@
variant and version number set according to RFC 4122, overriding bits in the
given *hex*, *bytes*, *bytes_le*, *fields*, or *int*.
+ Comparison of UUID objects are made by way of comparing their
+ :attr:`UUID.int` attributes. Comparison with a non-UUID object
+ raises a :exc:`TypeError`.
+
+ ``str(uuid)`` returns a string in the form
+ ``12345678-1234-5678-1234-567812345678`` where the 32 hexadecimal digits
+ represent the UUID.
:class:`UUID` instances have these read-only attributes:
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -292,6 +292,10 @@
badtype(lambda: setattr(u, 'clock_seq_low', 0))
badtype(lambda: setattr(u, 'node', 0))
+ # Comparison with a non-UUID object
+ badtype(lambda: u < object())
+ badtype(lambda: u > object())
+
def test_getnode(self):
node1 = uuid.getnode()
self.assertTrue(0 < node1 < (1 << 48), '%012x' % node1)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list