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 issue

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
Changes from 1 commit
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
Next Next commit
Improve perfomance of UUID.hex and UUID.__str__ by using bytes.hex()
  • Loading branch information
booqoffsky committed Mar 13, 2025
commit 1e2b4e3922072a6be47f645aa67423c00a22d0ca
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
0