8000 gh-131196: Improve perfomance of UUID.hex and UUID.__str__ by using bytes.hex() by booqoffsky · Pull Request #131197 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-131196: Improve perfomance of UUID.hex and UUID.__str__ by using bytes.hex() #131197

New i 8000 ssue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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:])
x = self.hex
return f'{x[:8]}-{x[8:12]}-{x[12:16]}-{x[16:20]}-{x[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 :attr:`uuid.UUID.hex` and :meth:`uuid.UUID.__str__ <object.__str__>`.
Loading
0