Skip to content

Commit cd88584

Browse files
committed
Improve perfomance of UUID.hex and UUID.__str__ by using bytes.hex()
1 parent de2f7da commit cd88584

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Lib/uuid.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,8 @@ def __setattr__(self, name, value):
321321
raise TypeError('UUID objects are immutable')
322322

323323
def __str__(self):
324-
hex = '%032x' % self.int
325-
return '%s-%s-%s-%s-%s' % (
326-
hex[:8], hex[8:12], hex[12:16], hex[16:20], hex[20:])
324+
hex = self.hex
325+
return f'{hex[:8]}-{hex[8:12]}-{hex[12:16]}-{hex[16:20]}-{hex[20:]}'
327326

328327
@property
329328
def bytes(self):
@@ -387,7 +386,7 @@ def node(self):
387386

388387
@property
389388
def hex(self):
390-
return '%032x' % self.int
389+
return self.bytes.hex()
391390

392391
@property
393392
def urn(self):

0 commit comments

Comments
 (0)