Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9038f43

Browse filesBrowse files
committed
bpo-29729: uuid.UUID now accepts bytes-like object
uuid.UUID doesn't require the 'bytes' argument to be an instance of bytes: accept bytes-like types, bytearray and memoryview for example.
1 parent d780b2d commit 9038f43
Copy full SHA for 9038f43

File tree

Expand file treeCollapse file tree

3 files changed

+8
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-1
lines changed

‎Lib/test/test_uuid.py

Copy file name to clipboardExpand all lines: Lib/test/test_uuid.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ def testIssue8621(self):
456456

457457
self.assertNotEqual(parent_value, child_value)
458458

459+
def test_bytes_like(self):
460+
u = uuid.uuid4()
461+
self.assertEqual(uuid.UUID(bytes=memoryview(u.bytes)), u)
462+
self.assertEqual(uuid.UUID(bytes=bytearray(u.bytes)), u)
463+
459464

460465
class TestInternals(unittest.TestCase):
461466
@unittest.skipUnless(os.name == 'posix', 'requires Posix')

‎Lib/uuid.py

Copy file name to clipboardExpand all lines: Lib/uuid.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
166166
if bytes is not None:
167167
if len(bytes) != 16:
168168
raise ValueError('bytes is not a 16-char string')
169-
assert isinstance(bytes, bytes_), repr(bytes)
170169
int = int_.from_bytes(bytes, byteorder='big')
171170
if fields is not None:
172171
if len(fields) != 6:
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
uuid.UUID now accepts bytes-like object. The constructor doesn't require the
2+
'bytes' argument to be an instance of bytes: accept bytes-like types,
3+
bytearray and memoryview for example.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.