Skip to content

Commit 25363cc

Browse files
committed
uuid: Use bytes.hex instead of binascii.hexlify.
Using `bytes.hex()` eliminates an import, and eliminates the call to `.decode()` to convert it to a str. Also run ruff format. Signed-off-by: Damien George <damien@micropython.org>
1 parent 883c4d9 commit 25363cc

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

python-stdlib/uuid/uuid.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import os
2-
import ubinascii
32

43

54
class UUID:
65
def __init__(self, bytes):
76
if len(bytes) != 16:
8-
raise ValueError('bytes arg must be 16 bytes long')
7+
raise ValueError("bytes arg must be 16 bytes long")
98
self._bytes = bytes
109

1110
@property
1211
def hex(self):
13-
return ubinascii.hexlify(self._bytes).decode()
12+
return self._bytes.hex()
1413

1514
def __str__(self):
1615
h = self.hex
17-
return '-'.join((h[0:8], h[8:12], h[12:16], h[16:20], h[20:32]))
16+
return "-".join((h[0:8], h[8:12], h[12:16], h[16:20], h[20:32]))
1817

1918
def __repr__(self):
2019
return "<UUID: %s>" % str(self)

0 commit comments

Comments
 (0)