https://github.com/python/cpython/commit/3a04be986a1adac4fb8d8780b959f60e51c15b8f
commit: 3a04be986a1adac4fb8d8780b959f60e51c15b8f
branch: main
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2025-09-17T13:31:51Z
summary:
gh-76760: test that `uuid.uuid1()` sets the version field (#139033)
files:
M Lib/test/test_uuid.py
M Lib/uuid.py
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index edce504fc4ba65..33045a78721aac 100755
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -590,6 +590,7 @@ def test_uuid1_safe(self):
# dependent on the underlying platform support. At least it cannot be
# unknown (unless I suppose the platform is buggy).
self.assertNotEqual(u.is_safe, self.uuid.SafeUUID.unknown)
+ self.assertEqual(u.version, 1)
@contextlib.contextmanager
def mock_generate_time_safe(self, safe_value):
@@ -612,24 +613,28 @@ def test_uuid1_unknown(self):
with self.mock_generate_time_safe(None):
u = self.uuid.uuid1()
self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown)
+ self.assertEqual(u.version, 1)
@unittest.skipUnless(os.name == 'posix', 'POSIX-only test')
def test_uuid1_is_safe(self):
with self.mock_generate_time_safe(0):
u = self.uuid.uuid1()
self.assertEqual(u.is_safe, self.uuid.SafeUUID.safe)
+ self.assertEqual(u.version, 1)
@unittest.skipUnless(os.name == 'posix', 'POSIX-only test')
def test_uuid1_is_unsafe(self):
with self.mock_generate_time_safe(-1):
u = self.uuid.uuid1()
self.assertEqual(u.is_safe, self.uuid.SafeUUID.unsafe)
+ self.assertEqual(u.version, 1)
@unittest.skipUnless(os.name == 'posix', 'POSIX-only test')
def test_uuid1_bogus_return_value(self):
with self.mock_generate_time_safe(3):
u = self.uuid.uuid1()
self.assertEqual(u.is_safe, self.uuid.SafeUUID.unknown)
+ self.assertEqual(u.version, 1)
def test_uuid1_time(self):
with mock.patch.object(self.uuid, '_generate_time_safe', None), \
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 313f2fc46cb346..c0150a59d7cb9a 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -737,6 +737,7 @@ def uuid1(node=None, clock_seq=None):
is_safe = SafeUUID(safely_generated)
except ValueError:
is_safe = SafeUUID.unknown
+ # The version field is assumed to be handled by _generate_time_safe().
return UUID(bytes=uuid_time, is_safe=is_safe)
global _last_timestamp
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]