Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ def __setattr__(self, name, value):
raise TypeError('UUID objects are immutable')

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

@property
def bytes(self):
Expand Down Expand Up @@ -387,7 +386,7 @@ def node(self):

@property
def hex(self):
return '%032x' % self.int
return self.bytes.hex()

@property
def urn(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve perfomance of UUID.hex and UUID.__str__ by using bytes.hex().
Loading